0% found this document useful (0 votes)
53 views2 pages

Exercise Exception Handling

This document discusses exception handling in Java code. It provides 3 code examples and asks what the output would be for each. The first example asks what would be output with different integer values passed to a method. The second asks what specific RuntimeException would be thrown by pieces of code. The third asks what would be displayed when running a full program that contains try/catch blocks and exceptions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Exercise Exception Handling

This document discusses exception handling in Java code. It provides 3 code examples and asks what the output would be for each. The first example asks what would be output with different integer values passed to a method. The second asks what specific RuntimeException would be thrown by pieces of code. The third asks what would be displayed when running a full program that contains try/catch blocks and exceptions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise Exception Handling

1. What is the output of the following code?

What would be the output if the line

int value = 30;


Were changed to
int value = 60;

2. What RunTimeException will each of the following program throws?

3. What is displayed in the console when running the program?

public class Test { 


public static void main(String[] args) {
try { 
p(); 
System.out.println("After the method call"); 

catch (RuntimeException ex) {
System.out.println("RuntimeException"); 

catch (Exception ex)
{ System.out.println("Exception"); 


 
static void p() throws
Exception { try { 
String s = "5.6"; 
Integer.parseInt(s); // Cause a NumberFormatException 
 
int i = 0; int
y = 2 / i; 
System.out.println("Welcome to Java"); 

catch (RuntimeException ex)
{ System.out.println("RuntimeException"); 

catch (Exception ex) { System.out.println("Exception"); 


You might also like