Exceptions - PowerPoint PPT Presentation

1 / 3
About This Presentation
Title:

Exceptions

Description:

... exception keywords: throws, throw, try, catch, and finally. Ex. try. int number = Integer.ParseInt ... try-block terminates when an exception is thrown. ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 4
Provided by: Sel852
Category:
Tags: exceptions | try

less

Transcript and Presenter's Notes

Title: Exceptions


1
Exceptions
  • Java exception keywords throws, throw, try,
    catch, and finally
  • Ex.
  • try
  • int number Integer.ParseInt(stringField.
    getText())
  • resultField.setText(Doubled value is
    (2number))
  • catch (NumberFormatException nfe)
  • resultField.setText(Error in number
    nfe.toString() )
  • try-block terminates when an exception is thrown.
  • throw statement is usually associated with an
    if clause.
  • Ex.
  • public static int ParseInt(String s)
  • throws NumberFormatException
  • code for the method
  • throw new NumberFormatException()
  • etc

2
Exceptions - continued
  • Java Exception Inheritance Class
    approximately 30 total
  • checked means that you must deal with them or
    your program will not compile
  • Throwable
  • Error (unchecked)
  • LinkageError
  • VirtualMachineError
  • OutofMemoryError
  • Exception (all, checked, except for
    RuntimeException)
  • RunTimeException (unchecked)
  • ArithmeticException
  • IndexOutofBoundException
  • ArrayIndexOutofBoundsException
  • IllegalArgumentException
  • NumberFormatException
  • IOException (checked)
  • FileNotFoundException
  • MalformedURLException
  • InterruptedException (checked)

3
Exceptions - continued
  • Three cases related to throw
  • try-catch
  • Relayed to a higher method using throws
  • Not within method header or try-catch block
  • arrayIndexOutofBoundsException thrown when array
    boundaries overrun
  • One can try all exceptions of a class
  • Ex.
  • try
  • //some code
  • catch (Exception e)
  • //handle it
  • finally Used to ensure that a final action is
    applied to an exiting method, such as closing
    files.
Write a Comment
User Comments (0)
About PowerShow.com