public class ExceptionExOther {
public void methodA() throws UserDefinedException
{
try
{
System.out.println("Inside MethodA");
throw new UserDefinedException("Demo");
}
finally
{
System.out.println("MethodA's finally");
}
}
public static void main(String[] args) {
ExceptionExOther ex=new ExceptionExOther();
try {
ex.methodA();
} catch (UserDefinedException e) {
System.out.println("Caught "+e);
}
}
}
User Defined Exception
public class UserDefinedException extends Exception {
private String string;
public UserDefinedException(String str)
{
string=str;
}
public String toString()
{
return "UserDefinedException "+string;
}
}
0 comments:
Post a Comment