Most common types of exception

TOP TEN EXCEPTIONS

On the basis of source who triggers exception, all exceptions are divided into two types:

• JVM Exception

• Programmatic Exception

JVM Exception:

The exception which are created by jvm automatically when an event occurs is known as JVM exception.

e.g. ArrayIndexOutOfBound exception

Programmatic Exception:

The exception which are raised by either programmer or API developer is known as programmatic exception. e.g. IllegalArgument Exception.

1. ArrayIndexOutOfBound Exception:

It is a child class of runtime exception and hence it is unchecked.raised automatically by jvm whenever we are trying to access the array element with out of range index.

                    Int[] a =new int[10];

                    System.out.println(a[100]);

2. NullPointer Exception:

It is a child class of runtime exception and hence unchecked.it arises when we perform an action on null.e.g.

                   String s=null;

                   System.out.println(String.length());

3. StackOverFlowError:

It is a child class of error and hence unchecked.it arises whenever we are trying to perform recursive method invocation.e.g.

                              Class test{

                                      Public static void m1(){
                                                       m2();
                                                            }
                                      Public static void m2(){
                                                            m1();
                                                 }
                                      Public static void main(String[]args){
                                                       m1();
                                                                     }

4. NoClassDefFoundError:

It is a child class of error and hence unchecked.it arises whenever jvm unable to find the required class.e.g.

                        Java example 

                  Example class is not present in the folder.

5. ClassCastException:

It is the child class of runtime exception and hence unchecked.it arises whenever are trying to typecast parent object to child type.e.g.

                 String s=new String(“aaa”);

                   Object o=(object) s;
                   Object o=new object();
                    String s=(String) o;

6. ExceptionInInitializerError:

It is the child class of runtime exception and hence unchecked.it arises while performing initialization of static variable and while executing static blocks.

7. IllegalArgumentException:

It is the child class of runtime exception and hence unchecked.it is raised explicitly by the programmer or by API developer to indicate that a method is invoked with invalid argument.e.g.

Thread t=new Thread();

t.setpriority(100);

8. NumberFormatException:

It is the child class of runtime exception and hence unchecked.it is raised by the programmer or API developer to indicate that we are trying to convert string to number type, but string is not formatted.e.g.

Int i=Integer.parseInt(“ten”);

9. IllegalStateException:

It is the child class of runtime exception and hence unchecked.it is raised by the programmer or API developer to indicate that a method is invoked in appropriate time.

10. AssertionError:

It is the child class of error and hence unchecked.it is raised by the programmer or API developer to indicate that assert statement fails.e.g.

                    Assert(false);


Last updated:9/4/2018 6:22:59 AM
Anonymous User

Anonymous User

I am a content writter !

0 Comments

Leave Comment