
Try Catch + java-visual
Quiz
•
Computers
•
Professional Development
•
Hard
ANIL KUMAR
FREE Resource
74 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the error message in the screenshot?
Answer explanation
The screenshot shows a Java program that is trying to connect to a MySQL database. However, there is an error in the code that is causing the program to crash. The error message is "Java: unreported exception java.sql.SQLException: must be caught or declared to be thrown". This means that the program is not handling the SQLException exception correctly. The exception should either be caught and handled, or it should be declared so that the compiler knows about it.
2.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will happen if the catch block is not executed in the code snippet shown in the image?
Answer explanation
The catch block is not mandatory in Java. If an exception is thrown in a try block and there is no catch block to handle it, the exception will simply be propagated to the calling method. In this case, the clickonSignIn() method will return without printing anything to the console. The rest of the code in the program will continue to execute as normal.
3.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will happen if the user enters an empty string as input in the code snippet shown in the image?
Answer explanation
The ArrayIndexOutOfBoundsException exception will be thrown if the user enters an empty string as input. This is because the split() method will try to split the empty string into two parts, but there will be no parts to split. The exception will be caught by the catch block and the program will print "str1 str2" to the console.
4.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will be the output of the code snippet shown in the image?
Answer explanation
The code snippet in the image will print "Something caught" to the console. This is because the try block will throw an ArithmeticException exception when the result = 1/0 statement is executed. The ArithmeticException exception will be caught by the catch block and the program will print "Something caught" to the console. The finally block will also be executed, but it will not print anything to the console.
5.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the purpose of the throw new RequestException(e) statement in the code snippet shown in the image?
Answer explanation
The throw new RequestException(e) statement is used to throw a new RequestException exception. This is done in the finally block because the RequestException exception may have been thrown in the try block and not caught in the catch block. By throwing the RequestException exception in the finally block, it is guaranteed that the exception will be propagated to the calling method.
6.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the output of the code snippet shown in the image?
Answer explanation
The code snippet in the image will print all of the options to the console. This is because the try block will throw a NullPointerException exception when the str.length() method is called on the str variable, which is null. The NullPointerException exception will be caught by the catch block and the program will print "java.lang.NullPointerException" to the console. The finally block will also be executed and it will print "finally block always gets executed" to the console.
7.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the error message in the screenshot?
Answer explanation
The screenshot shows a Java program that is trying to divide 4 by 0. This is an ArithmeticException, which is an error that occurs when a mathematical operation is performed on a number that is zero. The error message is "Java: unreported exception java.lang.ArithmeticException: divide by zero". This means that the program is not handling the ArithmeticException exception correctly. The exception should either be caught and handled, or it should be declared so that the compiler knows about it.
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
6 questions
FOREST Self-Discipline
Lesson
•
1st - 5th Grade
7 questions
Veteran's Day
Interactive video
•
3rd Grade
20 questions
Weekly Prefix check #2
Quiz
•
4th - 7th Grade
Discover more resources for Computers
10 questions
Identifying Phishing Emails Quiz
Quiz
•
Professional Development
14 questions
2019 Logos
Quiz
•
Professional Development
7 questions
Tone and Mood Quick Check
Quiz
•
Professional Development
32 questions
Abbreviations and Equivalents
Lesson
•
6th Grade - Professio...
5 questions
11.4.25 Student Engagement & Discourse
Lesson
•
Professional Development
