Professional Documents
Culture Documents
Try {
Error lines of code
}
Catch{
Solution for the Exception
}
Finally{
It contains impotant message
}
Each and Every Exception in java is a class which is present inside the
java.lang package.
package org.emp;
String s = "java";
try {
System.out.println(s.charAt(5));
}catch (StringIndexOutOfBoundsException e) {
System.out.println(e);
System.out.println("done");
package org.emp;
String s = "java";
try {
System.out.println(s.charAt(5));
}catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}catch (Exception e) {
System.out.println("done");
}
}
package org.emp;
String s = "java";
try {
System.out.println(5);
}catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}catch (Exception e) {
}finally {
System.out.println("handled");
}
System.out.println("done");
package org.emp;
String s = "java";
try {
System.out.println(2);
try {
System.out.println(s.charAt(5));
} catch (Exception e) {
System.out.println(e);
} finally {
System.out.println("inner finally");
}
} catch (Exception e) {
System.out.println(e);
} finally {
System.out.println("outer finally");