class MyException extends Exception { // define my own type of Exception public MyException(String s) { // can just use Exception itself for simple cases super(s); // but need own definitions for bigger subsystems } } public class Except { public static void main(String args[]) { try { function4(); // no cascading ifs, nice-and-clean function5(); // function calls are just inline as if everything is OK function6(); } catch (MyException e) { // if an Exception is thrown, it will be caught here System.out.println(e.getMessage()); // note the declaration of the variable: MyException e } // Exceptions store error Strings which are accessed } // via getMessage() private static void function4() throws MyException { // must declare any possible Exception it might throw } private static void function5() throws MyException { } private static void function6() throws MyException { throw new MyException("error: 49"); // here's an actual error situation, note the String } // this will be caught in the main }