1In java exception is an object. Exceptions are created when an abnormal
2situations are arised in our program. Exceptions can be created by JVM or
3by our application code. All Exception classes are defined in java.lang.
4In otherwords we can say Exception as run time error.
5
1An exception is an event, which occurs during the execution of a
2program, that disrupts the normal flow of the program's instructions.
1In java exception is an object. Exceptions are created when an abnormal
2situations are arised in our program. Exceptions can be created by JVM or
3by our application code. All Exception classes are defined in java.lang.
4In otherwords we can say Exception as run time error. I use try & catch blocks
5to handle any exceptions in my code.
6 I am familiar with major checked and unchecked exceptions and
7 handle it accordingly to make my code execution smooth
1
2public class Exception8 {
3public static void main(String[]args)
4{
5 fun1();
6 fun2();
7}
8static void fun1()
9{
10 fun3();
11}
12static void fun2()
13{
14 fun3();
15}
16static void fun3()
17{
18 try {
19 System.out.println(20/0);
20 }
21 catch(ArithmeticException e)
22 {
23 System.out.println("Zero divison ");
24 }
25}
26}
27
11.Unchecked: occurs during run time
22.Checked Exceptions:occurs during the compile time.
3needs to be handled IMMEDIATELY
4Exception handling: try & catch: blocks, used for handling the exception
5
6throws keyword is used within the method signature
7disadvantage is: throws keyword whoever calls the method
8will have to handle the exception again but with
9try/catch you handle once. Try/catch is better way to handle it
10in utility class. Next time you call method you don’t get any exceptions
11
12most common Exception like NullPointerExceptio,
13ArrayIndexOutOfBound, ClassNotFoundException, IOException.
14are unchecked and they are descended from java.lang.RuntimeException
15In Selenium: nosuchelement, nostaleexception, nosuchaframe
16In SQL: SQL exception
1We can handle exceptions in either of the two ways :
21) By specifying try catch block where we can catch the exception.
32) Declaring a method with throws clause