throw

PHOTO EMBED

Wed Nov 01 2023 06:19:15 GMT+0000 (Coordinated Universal Time)

Saved by @dsce

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());
		}
	}
}
content_copyCOPY