presentation23 - Exception (2) Soheil Hassas Yeganeh...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Exception (2) Soheil Hassas Yeganeh Computer Engineering Department Sharif University of Technology A Code, Many Errors 2 Devide.java class Devide { public static void main (String args){ int i = Integer.valueOf(args[0]); int j = Integer.valueOf(args[1]); int k = i / j; System.out.println(k); } } A Code, Many Errors • This program has more than 3 potential errors : • Array index out of bound : args[0] and args[1] • Number format error : Integer.valueOf • Division by zero : i / j 2 Devide.java class Devide { public static void main (String args){ int i = Integer.valueOf(args[0]); int j = Integer.valueOf(args[1]); int k = i / j; System.out.println(k); } } RuntimeException 3 RuntimeException • RuntimeException is a direct child of Exception. • RuntimeExceptions is the only Throwable that can not be caught in a function, and does not need any throws clause . • ArithmeticException, ArrayIndexOutOfBoundsException, and NullPointerException inherit RuntimeException. 3 RuntimeException Sample 4 Devide.java class Devide { public static void main (String args){ throw new RuntimeException(“Test”); } } RuntimeException Sample • The main function does not need throws ! 4 Devide.java class Devide { public static void main (String args){ throw new RuntimeException(“Test”); } } Multiple Catches 5 Devide.java class Devide { public static void main (String args){ try{ int i = Integer.valueOf (args[0]); }catch(ArrayIndexOutOfBoundsExc...
View Full Document

This note was uploaded on 11/21/2010 for the course COMPUTER S 003 taught by Professor Izadi during the Spring '10 term at Amirkabir University of Technology.

Page1 / 36

presentation23 - Exception (2) Soheil Hassas Yeganeh...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online