Error management and exception handling

Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Error management and exception handling JAVA :

Error management and exception handling JAVA BY: VINAY C (12YCSB6043) B C A 5 th Sem

INTRODUCTION:

INTRODUCTION A program rarely run successfully at its very first attempt, Errors are the wrong that can make a program go wrong. It is therefore important to detect and manage properly all the possible error condition in the program so that the program will not terminate or crash during execution.

Errors:

Errors Errors are classified into two categories : Compile-time errors Run-time errors Compile-time errors :- All syntax errors will be detected and displayed by the java compiler and therefore these errors are known as compile time errors Run-time errors :- Run time errors are type of errors which are occurred by dividing an integer by zero, trying to cast an instance of a class to one of its sub class Error may occurred in execution time . Abnormal termination of program . Wrong execution result.

Exception:

Exception Definition :- An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons, including the following: A user has entered invalid data. A file that needs to be opened cannot be found.

Exception Hierarchy:

Exception Hierarchy All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class The Exception class has two main subclasses: IOException class and Runtime Exception Class..

Exceptions:

Exceptions IO Exceptions Runtime Exceptions IO Exceptions IOException is any unexpected problem the compiler encounters while attempting to run a program. Possible problems the compiler may encounter are attempting to read from a file that does not exist, write to a file which has an invalid name (a slash or a question mark in the title should do it), or attempting to read the next token in a file when there are no more tokens. Runtime exception A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation.

Catching Exceptions:

Catching Exceptions A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. try/catch looks like the following: Try { //Protected code } catch( ExceptionName e1) { //Catch block }

The finally Keyword:

The finally Keyword The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred. A finally block appears at the end of the catch blocks and has the following syntax: try { //Protected code } catch(ExceptionType1 e1) { //Catch block } catch(ExceptionType2 e2) { //Catch block } catch(ExceptionType3 e3) { //Catch block } Finally { //The finally block always executes. }

Common Exceptions:

Common Exceptions JVM Exceptions Programmatic exceptions JVM Exceptions : - These are exceptions/errors that are exclusively or logically thrown by the JVM. Examples : NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, Programmatic exceptions : - These exceptions are thrown explicitly by the application or the API programmers Examples: IllegalArgumentException, IllegalStateException.

PowerPoint Presentation:

THANK YOU