MyException.java Source code

Java tutorial

Introduction

Here is the source code for MyException.java

Source

/*
 * Output:
 * 
 * caught MyException[10]
 *  
 */

class MyException extends Exception {
    private int detail;

    MyException(int a) {
        detail = a;
    }

    public String toString() {
        return "MyException[" + detail + "]";
    }
}

public class MainClass {
    public static void main(String args[]) throws Exception {
        try {
            throw new MyException(10);

        } catch (MyException e) {
            System.out.println("caught " + e);
        }
    }
}