SlideShare a Scribd company logo
1 of 14
Exception Handling
 Java Exceptions
 Generating Exceptions
Java Exceptions
• Exception
– an event, usually some form of error, which
happens during the normal course of
program execution
• Exception Handling
– object-oriented technique to manage such
errors that comprises a group of methods
Java Exceptions
• Identifying exception conditions pertinent to
the application
• Locating exception handlers to respond to
possible conditions
• Monitoring when such conditions occur
Java Exceptions
• ArithmeticException
– caused by math errors
• ArrayIndexOutOfBoundsException
– caused by a bad array index
• ArrayStoreException
– caused when a program tries to store the wrong
type of data in an array
• FileNotFoundException
– caused by an attempt to access a nonexistent file
Java Exceptions
• IOException
– caused by general I/O failures
• NullPointerException
– caused by referencing a null object
• NumberFormatException
– caused when a conversion between string and
number fails
• OutOfMemoryException
– caused when there is not enough memory to
allocate a new object
Java Exceptions
• SecurityException
– caused by a security violation
• StackOverflowException
– caused when a program attempts to access
a nonexistent character position in a string
Java Exceptions
• Errors
– not exactly exceptions, but problems that
occur beyond the user or programmer’s
control
– typically ignored in program codes because
there cannot be done anything about them
Java Exceptions
• Checked Exceptions
– normal errors that can occur during the
execution of a program
– include problems such as array bound errors
and floating point exceptions
– usually handled by code blocks
Java Exceptions
• Runtime Exceptions
– probably could have been avoided by the
programmer
– ignored at the time of compilation
Generating Exceptions
• Method Calls
– If a method or constructor is declared to
throw an exception, then calling that
method or constructor may result in an
exception of the declared class or a subclass.
– It is a compile-time error for a method body
to generate or throw, and not catch, an
exception that is declared in the throws
clause.
Generating Exceptions
• Method Calls
int method() throws IOException {
...
}
method(); //this can throw an IOException
Generating Exceptions
• Runtime Exceptions
– can occur even though the offending piece
of code does not declare that it throws such
an exception
– can be thrown by a language statement or a
method call
– NullPointerException and
ArrayIndexOutOfBoundsException
Generating Exceptions
• Runtime Exceptions
int a[];
...
//this can throw an
ArrayIndexOutOfBoundsExceptions
int i = a[100];
Generating Exceptions
• User Exceptions
– manually thrown by the programmer using
the throw statement
– takes a single argument which must be an object
that is a subclass of Throwable
throw new Exception(“Problem”);

More Related Content

What's hot

Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platformChamil Madusanka
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptionsSujit Kumar
 
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 javapriyankazope
 
Code review for secure web applications
Code review for secure web applicationsCode review for secure web applications
Code review for secure web applicationssilviad74
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptionsmyrajendra
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
Java Exception Handling and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and AppletsTanmoy Roy
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Java Exceptions Best Practices
Java Exceptions Best PracticesJava Exceptions Best Practices
Java Exceptions Best PracticesArtur Mkrtchyan
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
exception handling in java
exception handling in java exception handling in java
exception handling in java aptechsravan
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 

What's hot (20)

Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
Exception handling
Exception handling Exception handling
Exception handling
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Code review for secure web applications
Code review for secure web applicationsCode review for secure web applications
Code review for secure web applications
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptions
 
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 and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and Applets
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Exceptions Best Practices
Java Exceptions Best PracticesJava Exceptions Best Practices
Java Exceptions Best Practices
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
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 in java
Exception handling  in javaException handling  in java
Exception handling in java
 

Viewers also liked

Tv Industry Presentation.Mimd
Tv Industry Presentation.MimdTv Industry Presentation.Mimd
Tv Industry Presentation.Mimdvarun23oct
 
Excom Business Plan
Excom Business  PlanExcom Business  Plan
Excom Business Planvarun23oct
 
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용주상 황
 
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...Dr. Helen Paige
 
Preguntas frecuentes sobre facturas a clientes
Preguntas frecuentes sobre facturas a clientesPreguntas frecuentes sobre facturas a clientes
Preguntas frecuentes sobre facturas a clientesEsker Ibérica
 
COMPANY PROFILE- NiS Consultants
COMPANY PROFILE- NiS ConsultantsCOMPANY PROFILE- NiS Consultants
COMPANY PROFILE- NiS ConsultantsNiS Consultants
 
Facturas de cargo, las excepciones que no confirman la regla
Facturas de cargo, las excepciones que no confirman la reglaFacturas de cargo, las excepciones que no confirman la regla
Facturas de cargo, las excepciones que no confirman la reglaEsker Ibérica
 
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al año
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al añoCaso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al año
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al añoEsker Ibérica
 
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558งานอาคารฯ คณะวิทย์ มจพ.
 

Viewers also liked (14)

Tv Industry Presentation.Mimd
Tv Industry Presentation.MimdTv Industry Presentation.Mimd
Tv Industry Presentation.Mimd
 
Excom Business Plan
Excom Business  PlanExcom Business  Plan
Excom Business Plan
 
Presentation_NEW.PPTX
Presentation_NEW.PPTXPresentation_NEW.PPTX
Presentation_NEW.PPTX
 
ญี่ปุ่น
ญี่ปุ่นญี่ปุ่น
ญี่ปุ่น
 
Cuda project paper
Cuda project paperCuda project paper
Cuda project paper
 
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용
[경의선 숲길지기] '하이라인의 친구들' 사례조사 내용
 
LPA ด้าน 1 การบริหารจัดการ
LPA ด้าน 1 การบริหารจัดการLPA ด้าน 1 การบริหารจัดการ
LPA ด้าน 1 การบริหารจัดการ
 
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...
KM: Improving and Sustaining Quality - Some Opportunities and Challenges of I...
 
Preguntas frecuentes sobre facturas a clientes
Preguntas frecuentes sobre facturas a clientesPreguntas frecuentes sobre facturas a clientes
Preguntas frecuentes sobre facturas a clientes
 
COMPANY PROFILE- NiS Consultants
COMPANY PROFILE- NiS ConsultantsCOMPANY PROFILE- NiS Consultants
COMPANY PROFILE- NiS Consultants
 
Facturas de cargo, las excepciones que no confirman la regla
Facturas de cargo, las excepciones que no confirman la reglaFacturas de cargo, las excepciones que no confirman la regla
Facturas de cargo, las excepciones que no confirman la regla
 
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al año
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al añoCaso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al año
Caso de éxito: Schibsted Spain digitaliza el envío de 300.000 facturas al año
 
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558
วาระการประชุม คณะกรรมการบริหารความเสี่ยงคณะวิทยาศาสตร์ประยุกต์ ครั้งที่ 2/2558
 
Văn phòng google tại amsterdam
Văn phòng google tại amsterdamVăn phòng google tại amsterdam
Văn phòng google tại amsterdam
 

Similar to Um presentation (1)

exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2thenmozhip8
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.pptJAYESHRODGE
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptyjrtytyuu
 
Exception handling
Exception handlingException handling
Exception handlingMinal Maniar
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
A36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptA36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptpromila09
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allHayomeTakele
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in javajunnubabu
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingMuskanNazeer
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in JavaAnkit Rai
 
Chapter 5 Exception Handling (1).pdf
Chapter 5 Exception Handling (1).pdfChapter 5 Exception Handling (1).pdf
Chapter 5 Exception Handling (1).pdfFacultyAnupamaAlagan
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1Shinu Suresh
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024nehakumari0xf
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024kashyapneha2809
 

Similar to Um presentation (1) (20)

exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Exception handling
Exception handlingException handling
Exception handling
 
Java chapter 6
Java chapter 6Java chapter 6
Java chapter 6
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
A36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptA36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.ppt
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograaming
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Chapter 5 Exception Handling (1).pdf
Chapter 5 Exception Handling (1).pdfChapter 5 Exception Handling (1).pdf
Chapter 5 Exception Handling (1).pdf
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1
 
Exception handling
Exception handlingException handling
Exception handling
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
 

Um presentation (1)

  • 1. Exception Handling  Java Exceptions  Generating Exceptions
  • 2. Java Exceptions • Exception – an event, usually some form of error, which happens during the normal course of program execution • Exception Handling – object-oriented technique to manage such errors that comprises a group of methods
  • 3. Java Exceptions • Identifying exception conditions pertinent to the application • Locating exception handlers to respond to possible conditions • Monitoring when such conditions occur
  • 4. Java Exceptions • ArithmeticException – caused by math errors • ArrayIndexOutOfBoundsException – caused by a bad array index • ArrayStoreException – caused when a program tries to store the wrong type of data in an array • FileNotFoundException – caused by an attempt to access a nonexistent file
  • 5. Java Exceptions • IOException – caused by general I/O failures • NullPointerException – caused by referencing a null object • NumberFormatException – caused when a conversion between string and number fails • OutOfMemoryException – caused when there is not enough memory to allocate a new object
  • 6. Java Exceptions • SecurityException – caused by a security violation • StackOverflowException – caused when a program attempts to access a nonexistent character position in a string
  • 7. Java Exceptions • Errors – not exactly exceptions, but problems that occur beyond the user or programmer’s control – typically ignored in program codes because there cannot be done anything about them
  • 8. Java Exceptions • Checked Exceptions – normal errors that can occur during the execution of a program – include problems such as array bound errors and floating point exceptions – usually handled by code blocks
  • 9. Java Exceptions • Runtime Exceptions – probably could have been avoided by the programmer – ignored at the time of compilation
  • 10. Generating Exceptions • Method Calls – If a method or constructor is declared to throw an exception, then calling that method or constructor may result in an exception of the declared class or a subclass. – It is a compile-time error for a method body to generate or throw, and not catch, an exception that is declared in the throws clause.
  • 11. Generating Exceptions • Method Calls int method() throws IOException { ... } method(); //this can throw an IOException
  • 12. Generating Exceptions • Runtime Exceptions – can occur even though the offending piece of code does not declare that it throws such an exception – can be thrown by a language statement or a method call – NullPointerException and ArrayIndexOutOfBoundsException
  • 13. Generating Exceptions • Runtime Exceptions int a[]; ... //this can throw an ArrayIndexOutOfBoundsExceptions int i = a[100];
  • 14. Generating Exceptions • User Exceptions – manually thrown by the programmer using the throw statement – takes a single argument which must be an object that is a subclass of Throwable throw new Exception(“Problem”);