Try Catch + java-visual

Try Catch + java-visual

Professional Development

74 Qs

quiz-placeholder

Similar activities

Java Tokens Identifiers Keyword

Java Tokens Identifiers Keyword

Professional Development

69 Qs

GPF ZARA Webpage design

GPF ZARA Webpage design

Professional Development

70 Qs

Servlets, JSP & XML

Servlets, JSP & XML

Professional Development

70 Qs

Python Programming

Python Programming

Professional Development

75 Qs

Java Fundamentals

Java Fundamentals

Professional Development

78 Qs

Object oriented Programming

Object oriented Programming

Professional Development

70 Qs

Python Basic Test 01

Python Basic Test 01

Professional Development

70 Qs

C Aptitude-2

C Aptitude-2

University - Professional Development

75 Qs

Try Catch + java-visual

Try Catch + java-visual

Assessment

Quiz

Computers

Professional Development

Hard

Created by

ANIL KUMAR

FREE Resource

74 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Media Image
What is the error message in the screenshot?
Java: unreported exception javsql.SQLException: must be caught or declared to be thrown
Unhandled exception: java.sql.SQLException
Errors occurred while compling module 'sad'
javac 18.0.121 was used to compile java sources

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

Media Image
What will happen if the catch block is not executed in the code snippet shown in the image?
The program will print "Clicking on sing in Link" to the console.
The program will throw an Exception.
The program will continue to execute the rest of the code.
The program will exit unexpectedly.

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

Media Image
What will happen if the user enters an empty string as input in the code snippet shown in the image?
The program will print "str1 str2" to the console.
The program will throw an ArrayIndexOutOfBoundsException.
The program will continue to execute the do loop.
The program will exit unexpectedly.

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

Media Image
What will be the output of the code snippet shown in the image?
Something caught
ArithmeticException caught
Not quite finally
Finally

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

Media Image
What is the purpose of the throw new RequestException(e) statement in the code snippet shown in the image?
To throw a new RequestException exception.
To catch a RequestException exception.
To close the finally block.
To print the stack trace of the RequestException exception.

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

Media Image
What is the output of the code snippet shown in the image?
Outer try-catch block
java.lang.NullPointerException
finally block always gets executed
All of the above

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

Media Image
What is the error message in the screenshot?
Java: unreported exception javlang.ArithmeticException: divide by zero
Unhandled exception: java.lang.ArithmeticException
Errors occurred while compling module 'sad'
javac 18.0.121 was used to compile java sources

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
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?