You are on page 1of 4

Exception Handling

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.

Object – it is a super class of all java classes


Throwable – it is a super class of all Exception and Error
Exception – it is a super class of all exception

package org.emp;

public class Client {

public static void main(String[] args) {

String s = "java";

try {
System.out.println(s.charAt(5));
}catch (StringIndexOutOfBoundsException e) {

System.out.println(e);

System.out.println("done");

package org.emp;

public class Client {

public static void main(String[] args) {

String s = "java";

try {
System.out.println(s.charAt(5));
}catch (ArrayIndexOutOfBoundsException e) {

System.out.println(e);

}catch (Exception e) {

System.out.println(" user "+e);

System.out.println("done");

}
}

package org.emp;

public class Client {

public static void main(String[] x) {

String s = "java";

try {
System.out.println(5);
}catch (ArrayIndexOutOfBoundsException e) {

System.out.println(e);

}catch (Exception e) {

System.out.println(" user "+e);

}finally {
System.out.println("handled");
}

System.out.println("done");

package org.emp;

public class Client {

public static void main(String[] x) {

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");

You might also like