Show List

Quiz - Java Exceptions - 1

55%

Public Average Score
Select the right answer for below questions:

What is the purpose of exception handling in Java?
To handle syntax errors in the code
To handle runtime errors in the code
To handle logical errors in the code
None of the above
To handle runtime errors in the code

What is the base class for all exceptions in Java?
Throwable
Exception
Error
None of the above
Throwable

What is the difference between checked and unchecked exceptions in Java?
Checked exceptions are thrown by the Java Virtual Machine (JVM), while unchecked exceptions are thrown by the programmer
Checked exceptions are those which the programmer must explicitly handle, while unchecked exceptions are those which the Java Virtual Machine (JVM) automatically handles
Checked exceptions are those which are related to the logic of the program, while unchecked exceptions are those which are related to system errors
None of the above
Checked exceptions are those which the programmer must explicitly handle, while unchecked exceptions are those which the Java Virtual Machine (JVM) automatically handles

What is the purpose of the try-catch block in Java?
To catch exceptions thrown by the programmer
To catch exceptions thrown by the program logic
To catch exceptions thrown by the Java Virtual Machine (JVM)
All of the above
To catch exceptions thrown by the Java Virtual Machine (JVM)

What is the purpose of the finally block in Java?
To handle exceptions thrown by the Java Virtual Machine (JVM)
To execute code, regardless of whether an exception is thrown or not
To catch exceptions thrown by the programmer
None of the above
To execute code, regardless of whether an exception is thrown or not

What is the purpose of the throw keyword in Java?
To throw a runtime exception
To throw a checked exception
To throw an unchecked exception
All of the above
To throw a checked exception

What is the purpose of the throws keyword in Java?
To specify the exceptions that a method might throw
To catch exceptions thrown by the Java Virtual Machine (JVM)
To catch exceptions thrown by the programmer
None of the above
To specify the exceptions that a method might throw

What is the purpose of the throwable.printStackTrace() method in Java?
To print the stack trace of an exception
To print the cause of an exception
To print the message of an exception
None of the above
To print the stack trace of an exception

What is the purpose of the throwable.getMessage() method in Java?
To get the stack trace of an exception
To get the cause of an exception
To get the message of an exception
None of the above
To get the message of an exception

What is the difference between the throwable.getMessage() and throwable.printStackTrace() methods in Java?
The getMessage() method returns the message of an exception, while the printStackTrace() method prints the stack trace of an exception
The printStackTrace() method returns the message of an exception, while the getMessage() method prints the stack trace of an exception
Both the getMessage() and printStackTrace() methods print the message of an exception
None of the above
The getMessage() method returns the message of an exception, while the printStackTrace() method prints the stack trace of an exception

Submit
Retry
{"qz1-618774":"To handle runtime errors in the code","qz1-618775":"Throwable","qz1-618776":"Checked exceptions are those which the programmer must explicitly handle, while unchecked exceptions are those which the Java Virtual Machine (JVM) automatically handles","qz1-618777":"To catch exceptions thrown by the Java Virtual Machine (JVM)","qz1-618778":"To execute code, regardless of whether an exception is thrown or not","qz1-618779":"To throw a checked exception","qz1-618780":"To specify the exceptions that a method might throw","qz1-618781":"To print the stack trace of an exception","qz1-618782":"To get the message of an exception","qz1-618783":"The getMessage() method returns the message of an exception, while the printStackTrace() method prints the stack trace of an exception"}

    Leave a Comment


  • captcha text