Home Java Java-exception Unhandled Exception


Share on Google+Share on Google+

Unhandled Exception

Unhandled Exception are the exception that are thrown during the execution of program.

Unhandled Exception


Unhandled Exception are the exception  that are thrown  during the execution of program. These exception are never caught during the execution of program. This result in nasty Exception stack. Usually this type of exception is caught in try and catch block, but this is not possible to catch each and every exception in the program. There are some unavoidable exception that occurs when there is a mistake made by the client rather than it  occurred where it is thrown.Eventually,this is userdefined exception that not to be occurred

Unhandled Exception are categorized into different type-

1)Java .lang. Null Pointer Exception-. A java.lang.NullPointer Exception is thrown and not handled by any page.

2)com.jpmc.cig.arch.exception.CIGSystemException-The exception is thrown and not handled by any page flow and message is Application name is not provided by the URL.

3)Java.io.FileNotFoundException-This exception is thrown when a specified file is referred in the program  is not found.

4)Java.lang.illegalargument Exception-This exception is thrown when an illegal argument is sent to the method.


Let us Understand the Unhandled Exception with Example

In this code we try to explain  example declares an exception class Exception Check. The main method of class Check invokes the thrower method four times, that  causes the exceptions to be thrown three. The main method consists of try statement that try to catches the exception that the thrower throws. The thrower completes normally or abruptly, printed a message  describing the status of code.

   class ExceptionCheck extends Exception

  ExceptionCheck ( )


  super( );

  ExceptionCheck(String s) 



  class Check

  public static void main(String[] args)

  for (int j = 0; j < args.length; j++)


  System.out.println("Check\"" + args[j] +
"\" didn't throw an exception");

  catch (Exception e) 

  System.out.println("Check\"" + args[j] +
"\" threw a " + e.getClass() +
"\n with message: " + e.getMessage());
   static int thrower(String s) throws ExceptionCheck


  if (s.equals("divide")) 

  int j = 0;
   return j/j;

  if (s.equals("null")) {
  s = null;
 return s.length();

 if (s.equals("check")) 
  throw new CheckException("Test message");
  return 0;


   System.out.println("[thrower(\"" + s +
"\") done]");



Output on the Command Prompt

If we pass divide null not test  passed as argument to the method ,Command Prompt will show you

[thrower("divide") done]
C:\saurabh>javac Check.java
C:\saurabh java Check "divide" threw a class java.lang.ArithmeticException
           with message: / by zero
           [thrower("null") done]
           Check "null" threw a class java.lang.NullPointerException
           with message: null
           [thrower("not") done]
           Check "not" didn't throw an exception
           [thrower("check") done]
           Test "check" threw a class CheckException
        with message: Test message

If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 10, 2008

Related Tutorials

Ask Questions?    Discuss: Unhandled Exception  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image