//In acest exemplu se va defini o clasa "TestExceptie" care va //permite instantierea unor obiecte care descriu exceptii //diagnosticate de program.In clasa "Exemplu" metoda "arunca()" //poate sa arunce in anumite conditii un obiect de tipul //"TestExceptie".In metoda "main()" se poate provoca o exceptie de //tip "RunTimeException"(prin impartire cu zero) sau se poate apela //metoda "arunca()",care ar putea sa arunce un obiect de tip //"TestExceptie" import java.util.*; class TestExceptie extends Exception{ TestExceptie(String s){ super(s); } } class Exemplu{ static void arunca() throws TestExceptie{ if(true){ throw new TestExceptie("rau"); } } public static void main(String[] args){ int i=5; int j=0; try{ if(false){ arunca(); } else{ i=i/j; } } catch (RuntimeException e){ System.out.println("Runtime Exception"); } catch (TestExceptie e){ System.out.println("exceptie definita de programator"); System.out.println(e); } } }