Exceptions
- What is the output of this program?
public class exception_handling
{
public static void main(String args[])
{
try
{
int p, q;
q = 0;
p = 5 / q;
System.out.print("Love");
}
catch(ArithmeticException e)
{
System.out.print("You");
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
You
- Which of these keywords is used to manually throw an exception?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
throw
- What is the output of this program?
public class exception_Example
{
public static void main(String args[])
{
try
{
System.out.print("Interview" + " " + 15 / 0);
}
catch(ArithmeticException e)
{
System.out.print("Mania");
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
System.ou.print() function first converts the whole parameters into a string and then prints, before “Interview” goes to output stream 15 / 0 error is encountered which is cached by catch block printing just “Mania”.
- Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
If an exception occurs within the try block, it is thrown and cached by catch block for processing.
- What is the output of this program?
public class exception_Example
{
public static void main(String args[])
{
try
{
int p, q;
q = 0;
p = 13 / q;
System.out.print("welcome to");
}
catch(ArithmeticException e)
{
System.out.print("Interview");
}
finally
{
System.out.print(" Mania");
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
finally keyword is used to execute the code before try and catch block end.