Session 10 Exceptions in Java.ppt - Exception Handling in...

This preview shows page 1 - 9 out of 26 pages.

Exception Handling in Java 1 Exception Handling in Java
Exception Handling in Java 2 Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary
Exception Handling in Java 3 Introduction Users have high expectations for the code we produce. Users will use our programs in unexpected ways. Due to design errors or coding errors, our programs may fail in unexpected ways during execution
Exception Handling in Java 4 Introduction It is our responsibility to produce quality code that does not fail unexpectedly. Consequently, we must design error handling into our programs.
Exception Handling in Java 5 Errors and Error Handling An Error is any unexpected result obtained from a program during execution. Unhandled errors may manifest themselves as incorrect results or behavior, or as abnormal program termination. Errors should be handled by the programmer, to prevent them from reaching the user.
Exception Handling in Java 6 Errors and Error Handling Some typical causes of errors: Memory errors (i.e. memory incorrectly allocated, memory leaks, “null pointer”) File system errors (i.e. disk is full, disk has been removed) Network errors (i.e. network is down, URL does not exist) Calculation errors (i.e. divide by 0)
Exception Handling in Java 7 Errors and Error Handling More typical causes of errors: Array errors (i.e. accessing element – 1) Conversion errors (i.e. convert ‘q’ to a number) Can you think of some others?
Exception Handling in Java 8 Errors and Error Handling Traditional Error Handling 1. Every method returns a value (flag) indicating either success, failure, or some error condition. The calling method checks the return flag and takes appropriate action.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture