methods of throwable

PHOTO EMBED

Thu Dec 21 2023 23:58:25 GMT+0000 (Coordinated Universal Time)

Saved by @user01

public class ThrowableMessageExample{
	public static void main(String[]args){
		try{
			int result = divide(10,0);
		}
		catch(throwable t){
			String errorMessage = t.getMessage();
		if(errorMessage!=null){
			System.out.println("Caught on exception;"+errorMessage);
		}
		else{
			System.out.println("Caught on exception with no specific message");
		}
	}
	public static int divide(int c, int y) throws throwable{
		if(y==0){
			throwable error = new throwable("Divide by zero is not allowed");
			throw error;
		}
		return x/y;
	}
}
content_copyCOPY