NEW
Font size
S
M
L
XL
WorksheetsTry Catch + java-visual
Total questions: 74
Worksheet time: 25mins
Name
Class
Date
1.
What is the error message in the screenshot?
a)
Java: unreported exception javsql.SQLException: must be caught or declared to be thrown
b)
Unhandled exception: java.sql.SQLException
c)
Errors occurred while compling module 'sad'
d)
javac 18.0.121 was used to compile java sources
2.
What will happen if the catch block is not executed in the code snippet shown in the image?
a)
The program will print "Clicking on sing in Link" to the console.
b)
The program will throw an Exception.
c)
The program will continue to execute the rest of the code.
d)
The program will exit unexpectedly.
3.
What will happen if the user enters an empty string as input in the code snippet shown in the image?
a)
The program will print "str1 str2" to the console.
b)
The program will throw an ArrayIndexOutOfBoundsException.
c)
The program will continue to execute the do loop.
d)
The program will exit unexpectedly.
4.
What will be the output of the code snippet shown in the image?
a)
Something caught
b)
ArithmeticException caught
c)
Not quite finally
d)
Finally
5.
What is the purpose of the throw new RequestException(e) statement in the code snippet shown in the image?
a)
To throw a new RequestException exception.
b)
To catch a RequestException exception.
c)
To close the finally block.
d)
To print the stack trace of the RequestException exception.
6.
What is the output of the code snippet shown in the image?
a)
Outer try-catch block
b)
java.lang.NullPointerException
c)
finally block always gets executed
d)
All of the above
7.
What is the error message in the screenshot?
a)
Java: unreported exception javlang.ArithmeticException: divide by zero
b)
Unhandled exception: java.lang.ArithmeticException
c)
Errors occurred while compling module 'sad'
d)
javac 18.0.121 was used to compile java sources
8.
What is the purpose of the nested try block in the code snippet shown in the image?
a)
To catch the ArithmeticException exception that is thrown in the try block.
b)
To catch the NullPointerException exception that is thrown in the try block.
c)
To catch any exception that is thrown in the try block.
d)
To execute the code in the try block even if an exception is thrown.
9.
What is the output of the code snippet shown in the image?
a)
Nothing
b)
ArithmeticException
c)
NullPointerException
d)
Finally
10.
What is the purpose of the try block in the code snippet shown in the image?
a)
To execute code that may throw an exception.
b)
To execute code that will always throw an exception.
c)
To execute code that will only be executed if an exception is thrown.
d)
There is no purpose to the try block in this code snippet.
11.
What will be the output of the code snippet shown in the image?
a)
This always runs
b)
ArithmeticException
c)
NullPointerException
d)
Nothing
12.
What is the purpose of the try...catch...finally block in the program?
a)
To divide the program into two parts, the try block and the catch block.
b)
To handle exceptions that may occur in the try block.
c)
To ensure that the finally block is always executed, even if an exception occurs.
d)
To print a message to the console if an exception occurs.
13.
What is the output of the program?
a)
10
b)
20
c)
0
d)
The program will not compile.
14.
What is the output of the program if the user enters 10 for a and 0 for b?
a)
The program will print "Division by zero error".
b)
The program will print "Division by zero not possible".
c)
The program will print "Division of 10 by 0 is 0".
d)
The program will print "Program continues".
15.
What is the output of the program if the user enters localhost for host, root for user, and password for pass?
a)
The program will print "Connection successful".
b)
The program will print "Connection failed".
c)
The program will print "The user name or password is incorrect".
d)
The program will print "The host name is not found".
16.
What is the output of the program if the user enters any number other than 0 for numberOfUser?
a)
The program will print "Это не ноль!".
b)
The program will print "0".
c)
The program will print "The program will not compile".
d)
The program will throw an exception.
17.
What is the return value of the cell_data() method?
a)
null
b)
The string "ID: 158, HIS DESCRIPTION"
c)
The string "ID: 158"
d)
The string "HIS DESCRIPTION"
18.
What is the output of the program?
a)
The program will print "Inside finally block".
b)
The program will print "java.lang.ArithmeticException: / by zero".
c)
The program will print "The program will not compile".
d)
The program will print nothing.
19.
What is the purpose of the try...catch...finally block in the program?
a)
To divide the program into two parts, the try block and the catch block.
b)
To handle exceptions that may occur in the try block.
c)
To ensure that the finally block is always executed, even if an exception occurs.
d)
To print a message to the console if an exception occurs.
20.
What is the purpose of the finally block in the try...catch...finally block?
a)
To close the Scanner object.
b)
To print a message to the console if an exception occurs.
c)
To ensure that the try and catch blocks are always executed.
d)
To execute cleanup code regardless of whether or not an exception occurs.
21.
What is the purpose of the finally block?
a)
To print a message to the console.
b)
To execute cleanup code.
c)
To ensure that the try and catch blocks are always executed.
d)
All of the above.
22.
What is the output of the program if the user enters 10 for a and 0 for b?
a)
The program will print "Division by zero error".
b)
The program will print "Division by zero not possible".
c)
The program will print "Division of 10 by 0 is 0".
d)
The program will print "Program continues".
23.
What is the output of the program?
a)
The program will print "The program will not compile".
b)
The program will print "10/2 = 5".
c)
The program will print "10/0 = Infinity".
d)
The program will print "10/0 = NaN".
24.
What is the purpose of the catch block?
a)
To print a message to the console if an exception occurs.
b)
To execute cleanup code.
c)
To ensure that the try block is always executed.
d)
To handle exceptions that may occur in the try block.
25.
The code in the image shows a nested try-catch block. Which of the following exceptions will be caught by the inner catch block?
a)
ArrayIndexOutOfBoundsException
b)
ArithmeticException
c)
Both ArrayIndexOutOfBoundsException and ArithmeticException
d)
None of the above
26.
What is the purpose of the try-catch block?
a)
To divide 19 by 0
b)
To catch the ArithmeticException exception
c)
To print the result of the division
d)
To terminate the program if an exception is thrown
27.
What is the output of the code?
a)
A NullPointerException is thrown
b)
The string "A Caught NullPointerException" is printed to the console
c)
The string "**** Caught NullPointerException" is printed to the console
d)
The string "I am here....Got through it" is printed to the console
28.
Which of the following statements is true about the code?
a)
The code will always terminate with an exception.
b)
The code will always print the string "I am here....Got through it" to the console.
c)
The code will print the string "I am here....Got through it" to the console only if an exception is thrown.
d)
The code will never print the string "I am here....Got through it" to the console.
29.
Which of the following exceptions will be caught by the outer catch block?
a)
ArrayIndexOutOfBoundsException
b)
ArithmeticException
c)
NullPointerException
d)
None of the above
30.
The code in the image shows a method called getUnique. What is the purpose of the try-catch block in the method?
a)
To catch the FileNotFoundException exception.
b)
To catch the NullPointerException exception.
c)
To catch both the FileNotFoundException and NullPointerException exceptions.
d)
To do nothing.
31.
What is the purpose of the catch block in the code snippet shown in the image?
a)
To handle errors that occur in the try block.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
32.
What is the purpose of the finally block in the code snippet shown in the image?
a)
To execute cleanup code, even if an exception is thrown.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
33.
Which of the following statements is true about the try and catch blocks in the code snippet shown in the image?
a)
The try block will always be executed.
b)
The catch block will only be executed if an error occurs in the try block.
c)
The finally block will always be executed, even if an error occurs in the try or catch blocks.
d)
The try and catch blocks can be used to handle any type of exception.
34.
In the code snippet shown in the image, will the catch block for Ex1 be executed?
a)
Yes, if the exception thrown is assignable to Ex1.
b)
Yes, regardless of the type of exception thrown.
c)
No, only the catch block for Ex2 will be executed.
d)
The catch block for Ex1 will never be execute
35.
what will be the output of the program?
a)
The program will print "Problem im ArrayInducention has occured."
b)
The program will print "Exception in thread main java.lang.NullPointerException"
c)
The program will terminate abnormally.
d)
The program will print "The array is empty."
36.
what will be the output of the program?
a)
Excelente, el resultado de 3+ 5 es 8.
b)
El numero ingresado es invalido.
c)
El programa terminara de forma anormal.
d)
No se puede imprimir el resultado.
37.
What is the output of the Java program shown in the image?
a)
40
b)
0
c)
Exception in thread main java.lang.NumberFormatException: For input string: "4"
d)
The program will not compile.
38.
What is the output of the Java program shown in the image?
a)
100
b)
Invalid input, please try again:
c)
The program will not compile.
d)
The program will terminate abnormally.
39.
Which of the following statements is true about the code snippet shown in the image?
a)
The try block will always be executed.
b)
The catch block will only be executed if an error occurs in the try block.
c)
The finally block will always be executed, even if an error occurs in the try or catch blocks.
d)
The try and catch blocks can be used to handle any type of exception.
40.
Which of the following brace styles will be used for the try-catch block in the code snippet shown in the image?
a)
K&R/Kernel Style (Sun Style)
b)
Allman Style
c)
GNU Style
d)
Whitesmiths Style
41.
what will be the output of the program?
a)
Exception in thread main javlang.Exception: Handled in method throwException
b)
Finally is Always Executed
c)
Exception in thread main java.lang.Exception: Problem im ArrayInducention has occured.
d)
The program will terminate abnormally.
42.
What is the purpose of the finally block in the code snippet shown in the image?
a)
To execute cleanup code, even if an exception is thrown.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
43.
what will be the output of the program?
a)
10
b)
5
c)
The program will terminate abnormally.
d)
Nothing will be printed to the console.
44.
What is the purpose of the catch block in the code snippet shown in the image?
a)
To handle the ArrayIndexOutOfBoundsException exception.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
45.
what will be the output of the program?
a)
The program will compile successfully.
b)
The program will terminate abnormally.
c)
The program will print "Exception in thread main java.lang.NullPointerException" to the console.
d)
The program will print "10" to the console.
46.
What is the purpose of the finally block in the code snippet shown in the image?
a)
To execute cleanup code, even if an exception is thrown.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
47.
What is the output of the program shown in the image?
a)
The program will compile successfully.
b)
The program will terminate abnormally.
c)
The program will print "10" to the console.
d)
The program will print "Exception in thread main java.lang.ArithmeticException" to the console.
48.
What is the purpose of the catch block in the code snippet shown in the image?
a)
To handle the ArithmeticException exception.
b)
To print the error message to the console.
c)
To terminate the program.
d)
To continue execution of the program even if an error occurs.
49.
What is the value of the variable a after the code in the screenshot is executed?
a)
0
b)
1
c)
2
d)
3
50.
Which of the following is not printed to the console when the code in the screenshot is executed?
a)
Result of division: 0
b)
Exception in thread main java.lang.ArithmeticException: / by zero
c)
finally block always gets executed
d)
Unreachable catch block for FuntimeException. It is already handled by the catch block for Exception
51.
What is the purpose of the finally block in the code in the screenshot?
a)
To close the resources used by the objectWithResources object.
b)
To print the stack trace of the exception.
c)
To execute the code regardless of whether or not an exception is thrown.
d)
To catch any exceptions that are not caught by the catch block.
52.
What is the difference between the two code blocks in the screenshot?
a)
The code block without exception will always execute.
b)
The code block with exception will only execute if an exception is thrown.
c)
The code block with exception will always execute, but the code block without exception will only execute if an exception is not thrown.
d)
The code block with exception will only execute if a checked exception is thrown.
53.
What is the output of the code in the screenshot?
a)
1
b)
0
c)
An exception is thrown
d)
The program does not compile
54.
What is the output of the code in the screenshot?
a)
18
b)
-1
c)
finally block always gets executed
d)
The program does not compile
55.
What is the purpose of the do-while loop in the screenshot?
a)
To execute the code in the loop at least once, even if the condition is false.
b)
To execute the code in the loop as long as the condition is true.
c)
To execute the code in the loop until the condition is false.
d)
To execute the code in the loop a specific number of times.
56.
What is the output of the code in the screenshot?a
a)
An exception is thrown.
b)
The value of result is 0.
c)
The value of result is 1.
d)
The value of result is 2.
57.
What is the purpose of the if statement in the screenshot?
a)
To check if the value of a is equal to 1.
b)
To check if the value of a is greater than 0.
c)
To check if the value of a is less than 0.
d)
To check if the value of a is even.
58.
What is the output of the code in the screenshot?
a)
The value of a is 1
b)
The value of a is not equal to 1
c)
The value of a is 2
d)
The value of a is not equal to 2
59.
What is the output of the code in the screenshot?
a)
The value of a is 1
b)
The value of a is not equal to 1
c)
java.io.IOException handled
d)
SQLException handled
60.
What is the purpose of the try-catch block in the screenshot?
a)
To print the message "finally block is executed".
b)
To close any resources that were opened in the try block.
c)
To execute any cleanup code, regardless of whether or not an exception is thrown.
d)
To handle any exceptions that are thrown in the try block.
61.
What is the purpose of the for loop in the screenshot?a
a)
To print the numbers from 1 to 10.
b)
To print the even numbers from 1 to 10.
c)
To print the odd numbers from 1 to 10.
d)
To print the squares of the numbers from 1 to 10.
62.
What is the output of the code in the screenshot?
a)
18 is not a valid page number
b)
The page number is 18
c)
The page number is null
d)
Nothing is printed to the console.
63.
What is the purpose of the try-catch block in the screenshot?
a)
To print the message "finally block is executed".
b)
To close any resources that were opened in the try block.
c)
To execute any cleanup code, regardless of whether or not an exception is thrown.
d)
To handle any exceptions that are thrown in the try block.
64.
What is the purpose of the try block?
a)
To execute the code in the try block, even if an exception occurs.
b)
To catch any exceptions that occur in the try block and handle them gracefully.
c)
To ensure that the code in the try block is always executed, regardless of whether an exception occurs.
d)
To prevent any exceptions from occurring in the try block.
65.
What is the purpose of the finally block in the code snippet shown in the image?
a)
To close any resources that were opened in the try block, even if an exception occurs.
b)
To execute the code in the finally block, regardless of whether an exception occurs in the try block.
c)
To catch any exceptions that occur in the try block and handle them gracefully.
d)
To prevent any exceptions from occurring in the try block.
66.
What will happen if the server is down in the code snippet shown in the image?
a)
The code will execute without any problem.
b)
An exception will be thrown and the program will crash.
c)
The code in the catch block will be executed.
d)
The finally block will be execute
67.
what will be the output of the print() statement?
a)
Hello, world!
b)
NullPointerException
c)
IllegalArgumentException
d)
Nothing
68.
What is the output of the code snippet shown in the image?
a)
Finally called
b)
0
c)
1
d)
A NullPointerException is thrown
69.
What will be the output of the code snippet shown in the image?
a)
Output1
b)
Exception: by zero
c)
finally block always execute
d)
Nothing
70.
What is the purpose of the inner try-catch block?
a)
To catch any exceptions that are thrown in the outer try block.
b)
To provide a more specific catch block for a particular exception.
c)
To execute the code in the inner try block even if an exception is thrown in the outer try block.
d)
To ensure that the code in the inner try block is always executed, regardless of whether an exception is thrown.
71.
What is the output of the code snippet shown in the image?
a)
Result: 10
b)
Result: 5
c)
Divided by zero Exception
d)
The program will crash
72.
What is the purpose of the block in the middle of the flowchart?
a)
To find the first matching catch block.
b)
To find the most specific matching catch block.
c)
To find the catch block that was declared first.
d)
To find the catch block that was declared last.
73.
What is the error in the code snippet?
a)
The Throwable class is not a subclass of the Exception class.
b)
The catch block cannot catch a Throwable exception.
c)
The finally block cannot be used with a Throwable catch block.
d)
The try block cannot contain a Throwable exception.
74.
The code in the image shows a method enclosed with try-catch finally blocks. What is the output of the code?
a)
The code will throw an exception and terminate.
b)
The code will print "finally block always executed for resource clean-up" and then terminate.
c)
The code will print "finally block always executed for resource clean-up" and then return 0.
d)
The code will print "finally block always executed for resource clean-up" and then return 16.
Reset
