Java Exception
General info
Return to top
Exception catergories
- Throwable-->Exception for mild error, coverable, like IOException, NullPointerException
- Throwable -->Error for serious error condition, uncoverable, like AWTError,OutOfMemoryError
- Exception:
- Checked exception: must catch
- Unchecked exception: option for catch, like runtime exception
Return to top
Common Exceptions
Exception may occur on the conditions:
- The file you try to open does not exist
- The network connection is disrupted
- Operands being manipulated are out of prescribed ranges
- The class file you are interested in loading is missing
- An error class defines serious error conditions
Common Exceptions
- ArithmeticException
- NullPointerException
- NegativeArraySizeException
- ArrayIndexOutOfBoundsException
- SecurityException
Return to top
Use try/catch/finally
- throws Exception in the method declaration
- try/catch -- one or multiple exceptions
- try/finally
- try/catch/finally
- definately access block -- finally
Return to top
Create your own exception
- extends Exception
- one construtor should have a String as parameter to describe reason.
- call super(reason) in one of constructors.
- handle your own exception
Return to top
Develop programs to handle your own exceptions
- Enter some wrong data throw WrongInputException.
- Calculate result not satisfied, NotSatisfiedException.
- Limited work time, OverTimeException.
- etc.
Return to top