import java.util.*;
public class ThrowExcepTest
{
public static void main(String[] args)
{
System.out.println("Enter numerator");
int num = read();
System.out.println("Enter denominator");
int den = read();
display(num,den);
}
public static int read()
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
return n;
}
public static void display(int a,int b)
{
try{
System.out.println(a/b);
}
catch(ArithmeticException e){
System.out.println("\t\t\tDenominator is ZERO!!!\n\t\t\tDivision not possible");
}
finally{
Throwable t = new Throwable();
t.printStackTrace(System.out);
System.out.println(t.toString());
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter