Exceptions Handling in java

100 %
0 %
Information about Exceptions Handling in java
Science-Technology

Published on September 1, 2009

Author: sawanprasad

Source: authorstream.com

Exceptions Mr.Prasad Sawant Department Of Computer Science Prof .Ramkurshana More Arts, Commerce and Science College Akurdi. Mobile :9665755707 Email:sawanprasad@gmail.comBlog:http://prasadmsawant.blogspot.com/ : Exceptions Mr.Prasad Sawant Department Of Computer Science Prof .Ramkurshana More Arts, Commerce and Science College Akurdi. Mobile :9665755707 Email:sawanprasad@gmail.comBlog:http://prasadmsawant.blogspot.com/ Agenda : Agenda Define exception. Discuss what is meant by exception handing. Describe the try,catch and finally blocks. Examine multiple catch blocks. Explore nested try catch blocks. Explain the use of throw and throws keywords. Create user defined exception. What is exception? : What is exception? When an error is encountered during the execution of a program an exception is said to have occurred. Handling Exception : Handling Exception … IF B IS ZERO GO TO EROR C=A/B PRINT C GO TO EXIT ERROR: DISPLAY “CODE CAUSING ERROR DUE TO DIVISION BY ZERO” EXIT: END BLOCK THAT HANDLES ERROR HANDLING EXCEPTION IN JAVA : HANDLING EXCEPTION IN JAVA OBJECT THROWABLE Error Exception AWT ERROR Thread Death.. ……… SQLException ClassNotFoundException ……… System-Defined Exception : System-Defined Exception Raised implicitly by system because of illegal execution of program When cannot continue program execution any more Created by Java System automatically Exception extended from Error class and RuntimeException class [DivByZero.java] Slide 7: IndexOutOfBoundsException : When beyond the bound of index in the object which use index, such as array, string, and vector ArrayStoreException : When assign object of incorrect type to element of array NegativeArraySizeException : When using a negative size of array NullPointerException : When refer to object as a null pointer SecurityException : When violate security. Caused by security manager IllegalMonitorStateException : When the thread which is not owner of monitor involves wait or notify method Programmer-Defined Exception : Programmer-Defined Exception Exceptions raised by programmer Check by compiler whether the exception handler for exception occurred exists or not If there is no handler, it is error Sub class of Exception class The exception handling model : The exception handling model try { // code which is expected to throw an exception } Catch (exception e1) { /* If exception is thrown in the try block ,is of type e1,then perform necessary action here */ } Multiple catch block : Multiple catch block Class catch22 { public static void main(String args[]) { try { String num=args[0]; int numValue=Interger.parseInt(num); System.out.println(“The squre is ”+numValue*numvalue”); } catch(ArrayIndexOutOfBoundException e1) { System.out.println(“No argument is given!”); } catch(NumberFormatException e2) { System.out.println(“Not a number “); } } } C:>javac catch22 No argument is given! C:>javac catch22 a Not a number C:>javac catch22 3 The squre is 9 Nested try-catch : Nested try-catch … try { int num=args.length; try { int numValue=Integer.parseInt(args[0]); System.out.println(“The squre is “+numValue*numValue); } catch(NumberFormatExcption e1) { System.out.println(“Not a Number!”); } } catch (ArrayIndexOutOf BoundException e2) { System.out.println(“No arguments given!”); } …. C:>javac catch No argument is given! C:>javac catch22 a Not a number C:>javac catch22 3 The squre is 9 Finally block : Finally block The ‘finally ’block is guaranteed to run whether or not an exception occurs. The finally clauses of a try catch block will always execute ,even if there are return statement in the try catch part . Try block finally Catch block finally No exception Exception Using throws and throw : Using throws and throw Exception are thrown with the help of the ‘throw’ keyword .The ‘throw’ keyword is used to indicate that an exception has occurred .The operand of throw is an object of any class that is derived from the class ’Throwable’. The throws keyword is used to list the exception that method can throw.

Add a comment

Related presentations

Related pages

Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment
Read more

Java - Exceptions - Tutorials for Grav, RSpec, PyQt, Brand ...

Java Exceptions- Learning ... Based on these we have three categories of Exceptions you need to understand them to know how exception handling works in Java,
Read more

Exception Handling in Java - Javatpoint - A Solution of ...

Exception Handling in Java with checked, unchecked and errors with example and usage of try, catch, throw, throws and finally keywords.
Read more

Catching and Handling Exceptions (The Java™ Tutorials ...

This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment
Read more

Java Exception Handling | tutorials.jenkov.com

This tutorial series explains various aspects, tips and tricks of Java exception handling including exception hierarchies, checked and unchecked exceptions ...
Read more

Java Exception Handling Tutorial with Examples and Best ...

Related Posts:Catching Multiple Exceptions in single catch and Rethrowing…Java Exception Interview Questions and AnswersTry with Resource Example...
Read more

Exception handling - Wikipedia, the free encyclopedia

Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional conditions requiring ...
Read more

Ausnahmebehandlung – Wikipedia

Checked Exceptions. Bei Java gibt es als Weiterentwicklung der Ausnahme die „Checked Exception“ (dt. etwa: ... (Structured Exception Handling)
Read more

Java exception handling best practices - HowToDoInJava

There is no hard and fast rule for handling exceptions in any specific way. In struts-spring-hibernate project or any other project, you need to identify that
Read more

Java exception handling tutorial with example programs ...

Java exception handling tutorial: In this tutorial we will learn how to handle exception with the help of suitable examples. Exceptions are errors which ...
Read more