SlideShare a Scribd company logo
Exceptions
Exceptions
An exception is a problem that occurs
during the execution of a program.
In Java there a way to deal with those
problems.
Our friend, the Exception class.
There is an hierarchy of these
“problems” classes.
It reflects the different
type of errors that can occur.
https://docs.oracle.com/javase/7/docs/api/java/lang/package-tree.html
We can create our own Exceptions
classes to fulfil our own needs.
They are classes and they extend
from the Throwable class.
theTHROW
Methods can handle exceptions.
(we will see that later)
But if it does not handle an exception,
the method must declare it,
using the throws throws keyword
in his signature.
Causes and types
of exceptions
Some are caused by hardware resources.
Others by user error.
And many by a programmer error.
These are not exceptions at all, but
problems that arise beyond the
control of the user or the programmer.
You can rarely do anything about an
error.
Errors
Runtime
exceptions
A runtime exception could eventually
be avoided by the programmer. They
are ignored at the time of compilation.
Checked
exceptionsA checked exception is typically a user
error or a problem that cannot be
foreseen by the programmer. These
are the ones we should catch.
theTRYCATCH
Methods can detect
exceptions when they occur.
For this we should use the try/catch block.
It is placed around the code
that might generate an exception.
You always have to declare the type
of exception,
but being an object, exceptions
benefit from all the good things
of polymorphism.
A try block can be followed by
multiple catch blocks so you
can catch different exceptions.
Be careful with Throwable
hierarchy, blocks work similar to
switches.
thefinallykeyword
A finally block of code always executes,
whether or not an exception has occurred.
No matter what happens in the protected code,
it allows you to run any “cleanupish” code
that you want to execute.
public String getMessage()
Returns a detailed message about
the exception.
This message is initialized in the
constructor.
public String toString()
Returns the name of the class
concatenated with the result of
getMessage().
methodsThrowableclass
public Throwable getCause()
Returns the cause of the exception
as represented by a Throwable
object.
public void printStackTrace()
Prints the result of toString() along
with the stack trace to System.err,
the error output stream.
Exceptionsfilipe jorge
16 fev 2016

More Related Content

What's hot

Java Exception Handling and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and Applets
Tanmoy Roy
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Ankit Rai
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
chauhankapil
 
exception handling
exception handlingexception handling
exception handling
Manav Dharman
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
Nuha Noor
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
Ashwin Shiv
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
Narayana Swamy
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
Deepak Sharma
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
Graham Royce
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
Arjun Shanka
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
Swabhav Techlabs
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
Java2Blog
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Pratik Soares
 
Exceptional Handling in Java
Exceptional Handling in JavaExceptional Handling in Java
Exceptional Handling in Java
QaziUmarF786
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
Arriz San Juan
 
Java review: try catch
Java review: try catchJava review: try catch
Java review: try catch
Muzahidul Islam
 

What's hot (20)

Java Exception Handling and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and Applets
 
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
 
exception handling
exception handlingexception handling
exception handling
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
 
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
 
Exceptional Handling in Java
Exceptional Handling in JavaExceptional Handling in Java
Exceptional Handling in Java
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Java review: try catch
Java review: try catchJava review: try catch
Java review: try catch
 

Similar to summarizer16fev16_Exceptions

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
SakkaravarthiS1
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
DrHemlathadhevi
 
Java -Exception handlingunit-iv
Java -Exception handlingunit-ivJava -Exception handlingunit-iv
Java -Exception handlingunit-iv
RubaNagarajan
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
saman Iftikhar
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
EduclentMegasoftel
 
Java exceptions
Java exceptionsJava exceptions
Java exceptions
Pawan Kumar
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 
Exception handling
Exception handlingException handling
Exception handling
Tata Consultancy Services
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
Garuda Trainings
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
Chap12
Chap12Chap12
Chap12
Terry Yoast
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Exception handling
Exception handlingException handling
Exception handling
Garuda Trainings
 
Exception handling
Exception handlingException handling
Exception handling
Garuda Trainings
 
9781439035665 ppt ch11
9781439035665 ppt ch119781439035665 ppt ch11
9781439035665 ppt ch11
Terry Yoast
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
Rakesh Madugula
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
Shipra Swati
 

Similar to summarizer16fev16_Exceptions (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 -Exception handlingunit-iv
Java -Exception handlingunit-ivJava -Exception handlingunit-iv
Java -Exception handlingunit-iv
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Java exceptions
Java exceptionsJava exceptions
Java exceptions
 
Java exception
Java exception Java exception
Java exception
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Chap12
Chap12Chap12
Chap12
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
9781439035665 ppt ch11
9781439035665 ppt ch119781439035665 ppt ch11
9781439035665 ppt ch11
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 

summarizer16fev16_Exceptions

  • 2. An exception is a problem that occurs during the execution of a program.
  • 3. In Java there a way to deal with those problems. Our friend, the Exception class.
  • 4. There is an hierarchy of these “problems” classes. It reflects the different type of errors that can occur. https://docs.oracle.com/javase/7/docs/api/java/lang/package-tree.html We can create our own Exceptions classes to fulfil our own needs. They are classes and they extend from the Throwable class.
  • 6. Methods can handle exceptions. (we will see that later) But if it does not handle an exception, the method must declare it, using the throws throws keyword in his signature.
  • 7. Causes and types of exceptions
  • 8. Some are caused by hardware resources.
  • 9. Others by user error.
  • 10. And many by a programmer error.
  • 11. These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. You can rarely do anything about an error. Errors
  • 12. Runtime exceptions A runtime exception could eventually be avoided by the programmer. They are ignored at the time of compilation.
  • 13. Checked exceptionsA checked exception is typically a user error or a problem that cannot be foreseen by the programmer. These are the ones we should catch.
  • 15. Methods can detect exceptions when they occur. For this we should use the try/catch block. It is placed around the code that might generate an exception.
  • 16. You always have to declare the type of exception, but being an object, exceptions benefit from all the good things of polymorphism.
  • 17. A try block can be followed by multiple catch blocks so you can catch different exceptions. Be careful with Throwable hierarchy, blocks work similar to switches.
  • 18. thefinallykeyword A finally block of code always executes, whether or not an exception has occurred. No matter what happens in the protected code, it allows you to run any “cleanupish” code that you want to execute.
  • 19. public String getMessage() Returns a detailed message about the exception. This message is initialized in the constructor. public String toString() Returns the name of the class concatenated with the result of getMessage(). methodsThrowableclass public Throwable getCause() Returns the cause of the exception as represented by a Throwable object. public void printStackTrace() Prints the result of toString() along with the stack trace to System.err, the error output stream.
  • 20.