
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 Wayground
75 questions
TO dari MODUL PELATIHAN PTP 2018 v2-6a-7b

Quiz
•
Professional Development
78 questions
AWS Certified Solutions Architect Associate Exam Chapter 13 Quiz

Quiz
•
Professional Development
74 questions
Preparatorio 2º SMR1 1

Quiz
•
Professional Development
70 questions
1ºDAM/DAW - Sistemas Informáticos - UD5-UD7 - Prof. C. Boni

Quiz
•
University - Professi...
75 questions
COMPTIA IT 9

Quiz
•
Professional Development
76 questions
GCP EXAM

Quiz
•
Professional Development
70 questions
latihan soal TIK (office)

Quiz
•
1st Grade - Professio...
70 questions
H3CSE PostTest

Quiz
•
Professional Development
Popular Resources on Wayground
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
11 questions
Hallway & Bathroom Expectations

Quiz
•
6th - 8th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade