Computer Science 111 Fundamentals of Computer Programming I - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Computer Science 111 Fundamentals of Computer Programming I

Description:

Then there are run-time errors - situations arise during execution that we ... When a run-time error occurs, Java throws an exception. ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 12
Provided by: tomwh
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 111 Fundamentals of Computer Programming I


1
Computer Science 111Fundamentals of Computer
Programming I
  • Introduction to Java exception handling

2
News Alert
3
Run-time errors
  • There are certain kinds of errors that the
    compiler can not detect
  • First of all there are logic errors we simply
    make a mistake in the logic of our code. The
    compiler doesnt know how to play Blackjack.
  • Then there are run-time errors - situations
    arise during execution that we didnt anticipate
    and the compiler had no way to anticipate.
  • User inputs a zero for a divisor.
  • We try to access an array element using a
    subscript that is not within range
  • Etc.
  • What happens?

4
Run-time error example
5
The Black screen of death!
6
Java Exceptions
  • When a run-time error occurs, Java throws an
    exception.
  • We can write sections of code that catch the
    exception if it occurs and deal with it within
    the program.
  • Some parts of our Java code are required to
    anticipate and deal with errors this way.
  • An example would be when we are trying to use a
    file that may or may not exist.

7
Partial Class Hierarchy
Throwable
Exception
Error
RuntimeException
IOException
ArithmeticException
IndexOutOfBoundsException
8
Java Documentation
9
try-catch statements
  • With try-catch statements
  • There is a try block that contains the code we
    want to execute.
  • There is a catch block that specifies the
    exception type that we want to handle and the
    code to execute if the error occurs.

10
No black screen of death!
11
But, will they be here tomorrow?
Write a Comment
User Comments (0)
About PowerShow.com