
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
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
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
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
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
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
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
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
Similar Resources on Quizizz
71 questions
MEM16008 Computing Technology Training Quiz

Quiz
•
Professional Development
72 questions
generate random number + java

Quiz
•
Professional Development
70 questions
Programming Quiz

Quiz
•
Professional Development
72 questions
WP 16-23

Quiz
•
Professional Development
70 questions
PCNSA EXAM TRYOUT

Quiz
•
Professional Development
70 questions
Computer Basics Quiz

Quiz
•
Professional Development
70 questions
แบบทดสอบวิชา คอมพิวเตอร์ดนตรีเบื้องต้น

Quiz
•
Professional Development
70 questions
H3CSE PostTest

Quiz
•
Professional Development
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade