SlideShare a Scribd company logo
1 of 14
BCA 5th SEM 
DEEPAK SHARMA 
12KSSB6031
 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. There are 2 types of Errors. 
Namely, 
 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 occurred in execution time. 
 Abnormal termination of program. 
 Wrong execution result. 
 Provide an exception handling mechanism in 
language system. 
 Improve the reliability of application program. 
 Allow simple program code for exception check 
and handling into source.
Exception is an object thrown when a runtime 
error occurs in the program. 
 Class Exception 
 Class Runtime Exception 
 Class Error 
 Checked and un checked Exception
 Class Exception: The class Exception represents exceptions 
that a program would want to be made aware of during 
exception. 
 Class Runtime Exception : Runtime exceptions is a subclass 
of the exception class. The runtime exceptions are usually 
caused by program bugs i.e., they are faults in the program 
design. 
 Class Error: Subclasses of the java.lang.Error class define 
exceptions that indicate class linkage(linkage Error), thread 
(thread Death), and virtual machine(Virtual Machine Error) 
related problems.
Checked and unchecked Exception: Except for 
Runtime Exception, Error, and their subclasses, all 
exceptions are called checked exceptions. The 
method must either catch the exception and take the 
appropriate action, or pass the exception on to its 
caller.
try 
{ 
// statements that cause exception 
} 
catch(Exception e) 
{ 
//statements handling exception 
} 
finally // optional 
{ 
//file closing statement 
//connection closing statement 
}
public static void main(String str[]) 
{ 
int y=0; 
int x=1; 
//a division by 0 occurs here. 
int z=x/y; 
System.out.println(“ After division”); 
}
The first step in constructing an exception handler is 
to enclose the code that might throw an exception 
within a try block. 
General syntax:
Exception handlers with a try block are associated 
with one or more catch blocks directly after the try 
block. No code can be between the end of the try 
block and the beginning of the first catch block. 
Syntax: try 
{ 
} 
catch(ExceptionType name) 
{ 
}
The Finally block always executes when the try block exits. 
This ensures that the finally block is executed even if an 
unexpected exception occurs. It creates a block of code that 
will be executed after a try/catch block has completed and 
before the code following the try/catch block. Finally block will 
execute whether an exception is thrown or not. If an exception 
is thrown, the finally block will execute even if no catch 
statement matches the exception. 
Syntax: finally 
{ 
// statements in finally will get executed 
exception occurs or not. 
}
try block 
No Exception Exception Occurs 
finally catch 
finally
 Unchecked exceptions: exceptions derived from runtime 
exception class or automatically available, they need not to 
be included in any method “throw’s” list. These are called as 
unchecked exception because the compiler doesn't click to 
see, if a method handles or throws an exception. 
 Checked Exception: exception defined by java.lan that must 
be included in a method “throw’s” list ,if that method can 
generate one of these exception and doesn't handle itself are 
called Checked exception. 
 Eg: classNotFoundException 
 InterruptedException
THANK YOU

More Related Content

What's hot

Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapooja kumari
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapriyankazope
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handlingHemant Chetwani
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception HandlingLemi Orhan Ergin
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
exception handling in java
exception handling in java exception handling in java
exception handling in java aptechsravan
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaARAFAT ISLAM
 

What's hot (20)

exception handling
exception handlingexception handling
exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handling
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
exception handling in java
exception handling in java exception handling in java
exception handling in java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 

Viewers also liked

Exceptions Report - Project Management template
Exceptions Report - Project Management template Exceptions Report - Project Management template
Exceptions Report - Project Management template Simon Misiewicz
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling pptJavabynataraJ
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
BUSN7024_Project Management Plan_Example
BUSN7024_Project Management Plan_ExampleBUSN7024_Project Management Plan_Example
BUSN7024_Project Management Plan_ExampleVIVAIO
 
Do Languages Matter?
Do Languages Matter?Do Languages Matter?
Do Languages Matter?Bruce Eckel
 
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題teddysoft
 
2.software requirement specification
2.software requirement specification2.software requirement specification
2.software requirement specificationDeepak Sharma
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaManoj_vasava
 
07. Analytics & Reporting Requirements Template
07. Analytics & Reporting Requirements Template07. Analytics & Reporting Requirements Template
07. Analytics & Reporting Requirements TemplateAlan D. Duncan
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Riktig feilhåndtering (og ja, checked exceptions er skadelige)
Riktig feilhåndtering (og ja, checked exceptions er skadelige)Riktig feilhåndtering (og ja, checked exceptions er skadelige)
Riktig feilhåndtering (og ja, checked exceptions er skadelige)ilmyggo
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 

Viewers also liked (16)

Exceptions Report - Project Management template
Exceptions Report - Project Management template Exceptions Report - Project Management template
Exceptions Report - Project Management template
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
3.software testing
3.software testing3.software testing
3.software testing
 
BUSN7024_Project Management Plan_Example
BUSN7024_Project Management Plan_ExampleBUSN7024_Project Management Plan_Example
BUSN7024_Project Management Plan_Example
 
Do Languages Matter?
Do Languages Matter?Do Languages Matter?
Do Languages Matter?
 
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
搞懂Java例外處理的難題:Checked與Unchecked Exceptions不再是問題
 
2.software requirement specification
2.software requirement specification2.software requirement specification
2.software requirement specification
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasava
 
Management by exception
Management by exceptionManagement by exception
Management by exception
 
07. Analytics & Reporting Requirements Template
07. Analytics & Reporting Requirements Template07. Analytics & Reporting Requirements Template
07. Analytics & Reporting Requirements Template
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
MBO and MBE
MBO and MBEMBO and MBE
MBO and MBE
 
Riktig feilhåndtering (og ja, checked exceptions er skadelige)
Riktig feilhåndtering (og ja, checked exceptions er skadelige)Riktig feilhåndtering (og ja, checked exceptions er skadelige)
Riktig feilhåndtering (og ja, checked exceptions er skadelige)
 
Prince2 Methodology
Prince2 MethodologyPrince2 Methodology
Prince2 Methodology
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 

Similar to 7.error management and exception handling

UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingSakkaravarthiS1
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception HandlingAshwin Shiv
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxVeerannaKotagi1
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertionRakesh Madugula
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptionssaman Iftikhar
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingPrabu U
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handlingKuntal Bhowmick
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptxprimevideos176
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handlingKuntal Bhowmick
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaKavitha713564
 
8.Exception handling latest(MB).ppt .
8.Exception handling latest(MB).ppt      .8.Exception handling latest(MB).ppt      .
8.Exception handling latest(MB).ppt .happycocoman
 
Unit5 java
Unit5 javaUnit5 java
Unit5 javamrecedu
 
Exception Hnadling java programming language
Exception Hnadling  java programming languageException Hnadling  java programming language
Exception Hnadling java programming languageushakiranv110
 

Similar to 7.error management and exception handling (20)

UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and Multithreading
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Exception handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread ProgrammingException handling, Stream Classes, Multithread Programming
Exception handling, Stream Classes, Multithread Programming
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
8.Exception handling latest(MB).ppt .
8.Exception handling latest(MB).ppt      .8.Exception handling latest(MB).ppt      .
8.Exception handling latest(MB).ppt .
 
Unit5 java
Unit5 javaUnit5 java
Unit5 java
 
summarizer16fev16_Exceptions
summarizer16fev16_Exceptionssummarizer16fev16_Exceptions
summarizer16fev16_Exceptions
 
Exception Hnadling java programming language
Exception Hnadling  java programming languageException Hnadling  java programming language
Exception Hnadling java programming language
 
Exception handling
Exception handlingException handling
Exception handling
 

More from Deepak Sharma

More from Deepak Sharma (7)

8.flip flops and registers
8.flip flops and registers8.flip flops and registers
8.flip flops and registers
 
1.sdlc
1.sdlc1.sdlc
1.sdlc
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
9.cs instrset
9.cs instrset9.cs instrset
9.cs instrset
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packages
 
10.data transmission
10.data transmission10.data transmission
10.data transmission
 
4.software management
4.software management4.software management
4.software management
 

7.error management and exception handling

  • 1. BCA 5th SEM DEEPAK SHARMA 12KSSB6031
  • 2.  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. There are 2 types of Errors. Namely,  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.
  • 3.  Error occurred in execution time.  Abnormal termination of program.  Wrong execution result.  Provide an exception handling mechanism in language system.  Improve the reliability of application program.  Allow simple program code for exception check and handling into source.
  • 4. Exception is an object thrown when a runtime error occurs in the program.  Class Exception  Class Runtime Exception  Class Error  Checked and un checked Exception
  • 5.  Class Exception: The class Exception represents exceptions that a program would want to be made aware of during exception.  Class Runtime Exception : Runtime exceptions is a subclass of the exception class. The runtime exceptions are usually caused by program bugs i.e., they are faults in the program design.  Class Error: Subclasses of the java.lang.Error class define exceptions that indicate class linkage(linkage Error), thread (thread Death), and virtual machine(Virtual Machine Error) related problems.
  • 6. Checked and unchecked Exception: Except for Runtime Exception, Error, and their subclasses, all exceptions are called checked exceptions. The method must either catch the exception and take the appropriate action, or pass the exception on to its caller.
  • 7. try { // statements that cause exception } catch(Exception e) { //statements handling exception } finally // optional { //file closing statement //connection closing statement }
  • 8. public static void main(String str[]) { int y=0; int x=1; //a division by 0 occurs here. int z=x/y; System.out.println(“ After division”); }
  • 9. The first step in constructing an exception handler is to enclose the code that might throw an exception within a try block. General syntax:
  • 10. Exception handlers with a try block are associated with one or more catch blocks directly after the try block. No code can be between the end of the try block and the beginning of the first catch block. Syntax: try { } catch(ExceptionType name) { }
  • 11. The Finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. It creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. Finally block will execute whether an exception is thrown or not. If an exception is thrown, the finally block will execute even if no catch statement matches the exception. Syntax: finally { // statements in finally will get executed exception occurs or not. }
  • 12. try block No Exception Exception Occurs finally catch finally
  • 13.  Unchecked exceptions: exceptions derived from runtime exception class or automatically available, they need not to be included in any method “throw’s” list. These are called as unchecked exception because the compiler doesn't click to see, if a method handles or throws an exception.  Checked Exception: exception defined by java.lan that must be included in a method “throw’s” list ,if that method can generate one of these exception and doesn't handle itself are called Checked exception.  Eg: classNotFoundException  InterruptedException