Throwing Your Own Exceptions - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Description

Throwing Your Own Exceptions

Demo Code

public class MyException{
    public static void main(String[] args){
        try{/*from  w  w  w .  j  a va  2s .  c o m*/
            doSomething(true);
        }catch (Exception e){
            System.out.println("Exception!");
        }
    }

    public static void doSomething(boolean t)
        throws Exception
    {
        if (t)
            throw new Exception();
    }
}

Related Tutorials