Exception Handling Example
import java.io.IOException;
class MyException extends Exception
{
String mess;
public MyException(String message) {
super(message);
mess = message;
}
}
class MyTest
{
public static char read() throws IOException
{
char mychar = (char)System.in.read();
return mychar;
}
}
public class MyExceptionTest {
public static void main(String[] args) {
try {
throw new MyException("My First exception ");
}
catch(MyException me) {
System.out.println(me.getMessage());
// me.printStackTrace();
}
try {
char mych = MyTest.read();
System.out.println(mych);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("here ");
}
}
Comments
Post a Comment