Exception handling in java



An exception is any unwanted thing which may interrupt the control flow of the program.

Exception hierarchy

Types of Exceptions






There are mainly 2 types of Exceptions - checked or unchecked.




  1. Checked Exception:


    Exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword.


  2. UnChecked Exception:


    exceptions that are not checked at the compiled time.


In Java exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.





How to Handle Exception




They are handled by 5 keywords.

  1. try

  2. catch

  3. throw

  4. throws

  5. finally


Throws Keyword:





Throws Keyword and finally keyword



Comments

  1. I have checked your site and i've found some duplicate content,
    that's why you don't rank high in google, but there is a tool that can help you to create 100% unique articles, search for; Boorfe's tips
    unlimited content

    ReplyDelete

Post a Comment