COBOL | Java |
---|---|
*> Throw an exception declare exc = new Exception("Something is really wrong."); raise exc *> Catch an exception declare x y as binary-long try declare o as string = null display o[0] *> display first character catch ex as type Exception display ex finally display "Finally" end-try |
public class ExceptionHandling { public static void main(String[] args) throws Exception { Exception e = new Exception("Something is really wrong."); throw e; } public void nullReference() { try { String o = null; System.out.println(o.charAt(0)); } catch (Exception f) { System.out.println(f); } finally { System.out.println("Finally"); } } } |
Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.