Java Exceptions

Quiz
•
Computers
•
11th - 12th Grade
•
Medium
Joshua Donato
Used 63+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the code in the image. What will happen when the program is executed?
Program will crash.
Program will catch an exception in main.
Program will catch an exception in divide.
Program will run normally.
Answer explanation
An ArithmeticException is thrown by divide, but not caught in divide nor in main. Therefore, the program crashes.
2.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the code in the image. What happens if a user inputs 2?
An InputMismatchException is caught in main().
An IllegalArgumentException is caught in main().
The program crashes.
The program calculates and displays asin(2).
Answer explanation
An input of 2 triggers the if-statement in getInput, causing it to throw an IllegalArgumentException which is then caught in main.
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the code in the image. What happens if a user inputs the String "sqrt(2)"?
An InputMismatchException is caught in main().
An IllegalArgumentException is caught in main().
The program crashes.
The program calculates and displays asin(2).
Answer explanation
An input of sqrt(2) has letters and is therefore considered a String. This will cause Java to automatically throw an InputMismatchException, which is caught in main.
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the code in the image. What happens when this program is executed?
An Exception is caught in method1.
An Exception is caught in method2.
An Exception is caught in method3.
The program crashes.
Answer explanation
This program starts in main, then transfers control to method1, then to method3. An Exception is thrown by method3, and because it can't be caught in method3, Java tries method1 next, where it is caught.
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which of these best explains how try-catch blocks differ from throw statements?
try-catch blocks are handled locally, but throw statements can propagate through the call stack
try-catch block only catch exceptions, and throw statements only throw exceptions
try-catch blocks only try to execute code, but throw statements always work
try-catch blocks are written inside a function, but throw statements are written in the function header
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which of these is a checked exception?
OutOfMemoryError
StackOverflowError
ArithmeticException
IOException
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which of these is caused by integer division by zero?
ArithmeticException
ArrayIndexOutOfBoundsException
MathException
DivisionByZeroException
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
AlexaSkillProgram

Quiz
•
9th - 12th Grade
15 questions
Java Inheritance Quiz

Quiz
•
11th Grade
13 questions
BTEC Level 3 - Unit 1 - Topic 5 (Validating Data)

Quiz
•
12th Grade
15 questions
Mastering Exception Handling in Java

Quiz
•
12th Grade
11 questions
J277 Programming - Data Types

Quiz
•
9th - 11th Grade
15 questions
Python End of Topic Quiz

Quiz
•
8th Grade - University
10 questions
Java Strings

Quiz
•
1st Grade - Professio...
10 questions
Python Boolean and If

Quiz
•
9th - 12th Grade
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
Discover more resources for Computers
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
40 questions
LSHS Student Handbook Review: Pages 7-9

Quiz
•
11th Grade
20 questions
Scalars, Vectors & Graphs

Quiz
•
11th Grade
62 questions
Spanish Speaking Countries, Capitals, and Locations

Quiz
•
9th - 12th Grade
10 questions
Solving Equations Opener

Quiz
•
11th Grade
20 questions
First Day of School

Quiz
•
6th - 12th Grade
6 questions
Maier - AMDM - Unit 1 - Quiz 1 - Estimation

Quiz
•
12th Grade