2 Exception Handling
2 Exception Handling
2 Exception Handling
called as Exception.
package basicsOfException;
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
package basicsOfException;
int a = 10;
int b = 0;
int c = a / b;
System.out.println(c);
package basicsOfException;
int a = 10;
int b = 0;
try {
int c = a / b;
System.out.println(c);
}catch(ArithmeticException e) {
}
System.out.println("Main method execution Ended");
}
}
Types Of Exception :
1)Checked Exception
2)Unchecked Exception
Example 1 :
package typesOfException;
import java.io.FileNotFoundException;
import java.io.FileReader;
try {
FileReader fr = new FileReader("C:\\Users\\HP\\OneDrive\\
Desktop\\java\\Demo.java");
} catch (FileNotFoundException e) {
System.out.println("Catch Block");
}
Example :
package typesOfException;
import java.io.FileNotFoundException;
import java.io.FileReader;
try {
FileReader fr = new FileReader("C:\\Users\\HP\\OneDrive\\
Desktop\\java\\Demo11.java");
} catch (FileNotFoundException e) {
System.out.println("Catch Block");
}
2)Unchecked Exception : The Exception which are not checked by compiler is called
as Unchecked Exception.
Example :
package typesOfException;
int a = 10;
int b = 0;
int c = a / b;