Math107Ch8 - Introduction To Scientific Programming Chapter...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction To Scientific Programming Chapter 8 – Exception Handling
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 8 Slide 2 Lecture Overview On Exception Handling I. Basic Exception Handling A. B. Syntax C. Java Exception Classes I. Real-World Strategies A. Design-Time Error Trapping B. Un-Expected Error Control C. “Anticipated” Error Control I. Wrap-Up A. Book Case Study B. Extra Syntax
Background image of page 2
S.Horton/107/Ch. 8 Slide 3 I. Exception Handling - Background Handling errors is one of the most critical and practical aspects of programming today. The goal of error handling – no “lock-ups”/”blow- ups” or crashes! Recover (if you can) from errors. My theory: There are more ways for things to go wrong than right. Some believe that you can actually write as much code for error control and recovery as the application itself.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 8 Slide 4 Background (cont.) This is an evolving area, mostly because of public outcry about the poor performance of software! Historically, error handling has not been studied because not part of OOP “theory”. In Java, and other “recent” languages, actual syntax and classes have been built into the language to improve error handling. Sun is once again updating error control from the J2SE 1.4.2 SDK to J2SE 5.0!
Background image of page 4
S.Horton/107/Ch. 8 Slide 5 Java “Exception Handling” In Java, errors have been historically referred to as “Exceptions”. The most recent version has added one more level of abstraction - “Throwable”. Two things are built into Java: Syntax : try-catch-finally,… Classes : Exception, Throwable, … Java Documentation on Class Structure for Handling Errors (Oct. 2004)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 8 Slide 6 Types Of Program Errors Semantic These happen at design-time Syntax problems are caught by compiler (95% of the time) Logic These happen at both design-time and run-time Some can be caught by complier Examples include: typing errors, assignment mistakes, … Run-time These happen during program execution Can result in program “lock-up” or “blow-up”! Examples include: array indexing, file I/O, null pointers, math problems (division by zero),…
Background image of page 6
S.Horton/107/Ch. 8 Slide 7 Exception Handling Terminology An exception is an error or something in your program that is undefined or not suppose to happen. Throwing an exception is when either Java software or your code signals that an exception has happened. Catching an exception is the response to a thrown exception by executing a part of the program specifically written for that exception. The Exception Class is a predefined class in Java that contains a structure and methods to work with errors .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 8 Slide 8 Basic Error Handling Syntax: try-throw-catch try { <code to try> if(test condition) throw new Exception(“Error message to display"); <more code> } catch (Exception e) { <exception handling code> } <possibly more code>
Background image of page 8
S.Horton/107/Ch. 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/08/2011 for the course MATH 107 taught by Professor Christinashow during the Spring '08 term at Mesa CC.

Page1 / 34

Math107Ch8 - Introduction To Scientific Programming Chapter...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online