Exception Handling Oo28.

Slides:



Advertisements
Similar presentations
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Advertisements

Review Linked list: Doubly linked list, insertback, insertbefore Remove Search.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
1 CSC241: Object Oriented Programming Lecture No 28.
Exception Handling Introduction Exception handling is a mechanism to handle exceptions. Exceptions are error like situations. It is difficult to decide.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
Handling Errors with Exception (in Java) Project 10 CSC 420.
Slides prepared by Rose Williams, Binghamton University Chapter 9 More Exception Handling.
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 9 : Exception Handling King Fahd University of Petroleum & Minerals College of Computer.
CIS 270—Application Development II Chapter 13—Exception Handling.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
VB.Net - Exceptions Copyright © Martin Schray
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
© Mohamed Nuzrath Java Programming :: Chapter 6 :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme coordinator IT Lecturer.
CS212: Object Oriented Analysis and Design Lecture 20: Exception Handling-II.
1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Exceptions in OO Programming Introduction Errors Exceptions in Java Handling exceptions The Try-Catch-Finally mechanism Example code Exception propagation.
Exceptions an unusual condition – e.g. division by zero – e.g. file doesn't exist – e.g. illegal type – etc. etc… typically a run-time error – i.e. during.
Lecture 18B Exception Handling and Richard Gesick.
2.4 Exceptions n Detects try { //code that may raise an exception and/or set some condition if (condition) throw exceptionName; //Freq. A string } n Handles.
Eighth Lecture Exception Handling in Java
Java Exceptions a quick review….
Exception Handling in C++
C++ Exceptions.
16 Exception Handling.
Jim Fawcett CSE687-OnLine – Object Oriented Design Summer 2017
Jim Fawcett CSE687 – Object Oriented Design Spring 2001
Java Programming Fifth Edition
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Testing and Debugging.
Chapter 9 Recursion.
Part IX Fundamentals of C and C++ Programming Exception Handling
Object Oriented Programming COP3330 / CGS5409
Exceptions C++ Interlude 3
Chapter 14: Exception Handling
Exception Handling and
EE422C Software Implementation II
Exceptions Handling the unexpected
Exceptions with Functions
Chapter 12 Exception Handling and Text IO
Chapter 12 Exception Handling
Exceptions Problems in a Java program may cause exceptions or errors representing unusual or invalid processing. An exception is an object that defines.
Exception Handling and Reading / Writing Files
Exception Handling Chapter 9 Edited by JJ.
Data Abstraction: The Walls
Throwing and catching exceptions
Exceptions CSCE 121 J. Michael Moore
Part B – Structured Exception Handling
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Designing with Java Exception Handling
Object-Oriented Programming (OOP) Lecture No. 43
Fundaments of Game Design
Exception and Event Handling
Exceptions 10-May-19.
Lecture 9.
Chapter 11: Exception Handling
CMSC 202 Exceptions.
Exception Handling.
Exceptions and Exception Handling
Presentation transcript:

Exception Handling Oo28

Teaching Points Exception handling mechanisms Try-Throw-Catch

Error Handling Styles When we detect an error (exceptional condition) we can: Terminate the program Return a value representing the error Return a legal value and place the program in an illegal state Call an error function BUT…

Terminate the program Too Drastic! Many programs cannot just role over and fail Mission critical User can intervene to resolve error

Return a value representing the error Clutter in the main line of the code. It becomes hard to see main line of the logic is. Often there is no acceptable value which can easily be used (eg. The possible returns already cover the entire set of return values)

Return a legal value and place the program in an illegal state Clutter in the main line of the code. It becomes hard to see main line of the logic is. Probably must resort to global state variable (eg. C library errno) Example from C

Call an error function May clean up the logic a bit but we are really left with the same choices as before after the error call is made.

New Alternative Try-Throw-Catch Analogy - an alternate return mechanism

Try-Throw-Catch try block a program block in which an exception may be thrown it is uncluttered with error handling support any of the statements might throw an exception in which case the execution of the block stops with that statement

Try-Throw-Catch catch block a separate block in the body of the operation not normally executed designed to handle a specific exception this block is executed immediately after the specified exception is detected in the try block

Try-Throw-Catch throw statement stops execution of the operation at this statement throws an exception to the calling operation (I.e. does an alternate return with the exception value instead of the normal return value) the thown value is an object exceptions have their own types and are not related to the normal return type for the operation

Example Example is in Java but is essentially the same mechanism as C++

Teaching Points Exception handling mechanisms Try-Throw-Catch