package myexceptions;
public class ExceptionExample1 {
public static void printf(String arg0) throws MyException
{
if (arg0 == null || arg0.length() < 5)
throw new MyException("string too short");
System.out.println(arg0);
}
public static void main(String[] args) throws MyException
{
printf("hi");
try
{
printf("hello world");
printf("hi");
if (true)
{
throw new MyException("silly error");
}
System.out.println("Hello");
}
catch (MyException e)
{
System.out.println(e.errmessage);
}
catch (IndexOutOfBoundsException e)
{
}
catch (Exception e)
{
}
System.out.println("And then we come here");
}
}
class MyException extends Exception
{
String errmessage;
public MyException(String errmess)
{
errmessage = errmess;
}
}
Thursday, July 22, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment