Subclass Exception : Exception : java.lang : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.lang   » [  Exception  ]   
 



Subclass Exception

/*
 * 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);
    }
  }
}

           
       
Related examples in the same category
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.