68. User Define Exception or Custom Exception in JAVA
//User Define Exception or Custom Exception
class ExceptionA extends Exception
{
ExceptionA(String msg)
{
super(msg);
System.out.println(msg);
}
}
class ExceptionB extends Exception
{
ExceptionB(String msg)
{
super(msg);
System.out.println(msg);
}
}
class user_define_exc
{
public static void main(String[] args) throws ExceptionA, ExceptionB
{
int n = Integer.parseInt(args[0]);
if (n % 2 == 1) {
throw new ExceptionA("Problem");
}
else
{
throw new ExceptionB("Big Problem");
}
}
}
OUTPUT:
--------------------------------------------------------------------
java user_define_exc 5
Problem
Exception in thread "main" ExceptionA: Problem
at user_define_exc.main(user_define_exc.java:25)
---------------------------------------------------------------------
Comments
Post a Comment