Exception is an event that disrupts the normal flow of the program. Thus, it is important to handle these exceptions.
Like Java, Java Debugger (JDB) is also capable to handle these exceptions. The JDB catch command caught the exceptions at runtime.
Example of Exception Handling
In this example, we will handle arithmetic exception through JDB command on console.
JException.java
public class JException
{
int div(int a,int b)
{
return a/b;
}
public static void main( String...jtp)
{
JException obj=new JException();
System.out.println(obj.div(10,0));
}
}
- Compile the above program and create a JDB session.
- After the execution of program the following exception occurs:
0 comments:
Post a Comment