Results 1 to 2 of 2
  1. #1
    Java Example is offline Moderator
    Join Date
    Sep 2014
    Rep Power

    Default What is chained Exception in java programs?

    In this tutorial, we will discuss about the chained exception. Chained exception occurs whenever in a program the first exception causes an another exception. Java provides new functionality for chaining exceptions. Exception chaining (also known as "nesting exception") is a technique for handling the exception, which occur one after another i.e. most of the time is given by an application to response to an exception by throwing another exception. Typically the second exception is caused by the first exception. Therefore chained exceptions help the programmer to know when one exception causes another.

    The constructors that support chained exceptions in Throwable class are:
    Throwable initCause(Throwable)
    Throwable(String, Throwable)
    Throwable getCause()

    Java Code: Chained Exception example
    import java.util.*;
    class MyException extends Exception {
        MyException(String msg) {
    public class ChainExcep {
        public static void main(String args[]) throws MyException, IOException {
            try {
                int rs = 10 / 0;
            } catch (Exception e) {
                throw new MyException("Chained ArithmeticException");
    Output of the Program:

    What is chained Exception in java programs?-chained-exception.jpg
    Figure: Chained exception example

    This example has an user defined exception that throws an ArithmeticException and has been thrown under the catch handler. After throwing an exception, the handler will execute the statement of the catch block and then invoke the user defined constructor. Thus the implementation of chained exception is very helpful to the user to make a program or an application error and exception free.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: What is chained Exception in java programs?

    New functionality? Don't talk nonsense; it has been here since Java 1.1

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Run Java Programs
    By StevenR in forum New To Java
    Replies: 2
    Last Post: 02-20-2013, 10:33 AM
  2. Replies: 4
    Last Post: 01-09-2013, 03:05 PM
  3. Java Network Programs
    By sixxvirus in forum New To Java
    Replies: 5
    Last Post: 03-04-2012, 09:00 AM
  4. chained exception
    By simorgh in forum New To Java
    Replies: 15
    Last Post: 08-14-2010, 05:13 PM
  5. How to use chained exceptions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-04-2008, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts