Dr. Abraham. Exception Any problem that VB or OS could not handle Robust program A program that performs well not only under ordinary conditions but also.

Slides:



Advertisements
Similar presentations
Pearson Education, Inc. All rights reserved. 1.. Exception Handling.
Advertisements

Topics Introduction Types of Errors Exceptions Exception Handling
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Exception Handling Outline 13.1 Introduction 13.2 Exception-Handling Overview 13.3 Other.
Error Handling in.NET Exceptions. Error Handling Old way (Win32 API and COM): MyFunction() { error_1 = doSomething(); if (error_1) display error else.
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
CSE 1302 Lecture 21 Exception Handling and Parallel Programming Richard Gesick.
Exceptions Don’t Frustrate Your User – Handle Errors KR – CS 1401 Spring 2005 Picture – sysprog.net.
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Review Linked list: Doubly linked list, insertback, insertbefore Remove Search.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 13 Exception Handling.
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.
Exception Handling Yaodong Bi Exception Handling Java exception handling Try blocks Throwing and re-throwing an exception Catching an.
Mahmoud Rafeek Alfarra Computer Programming || Chapter 2: Exception handling.
Exception Handling 1 CISC6795, Spring Introduction 2 Exception – an indication of a problem that occurs during a program’s execution, for examples:
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Understand Error Handling Software Development Fundamentals LESSON 1.4.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
Exceptions and Exception Handling (2) Carl Alphonce CSE116.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
Exceptions. 2 Objectives Introduce C# exception handling –library exception types –custom exceptions Describe keywords used for exception handling –try.
 2002 Prentice Hall. All rights reserved Exception-Handling Overview Exception handling –improves program clarity and modifiability by removing.
 2009 Pearson Education, Inc. All rights reserved Exception Handling Many slides modified by Prof. L. Lilien (even many without explicit message).
 2006 Pearson Education, Inc. All rights reserved Exception Handling.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Exceptions. Many problems in code are handled when the code is compiled, but not all Some are impossible to catch before the program is run  Must run.
 2009 Pearson Education, Inc. All rights reserved Exception Handling.
 2006 Pearson Education, Inc. All rights reserved Exception Handling.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Object Oriented Programming
CIS 270—Application Development II Chapter 13—Exception Handling.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: Exception Handling Tujuan Instruksional Khusus: Mahasiswa dapat.
Slides Credit Umair Javed LUMS Web Application Development.
I NTRODUCTION TO PROGRAMMING Starting Out with Java: From Control Structures through Objects CS 146 Class Notes Fall 10.
VB.Net - Exceptions Copyright © Martin Schray
Introduction to Exception Handling and Defensive Programming.
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.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Unit 4 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Exceptions in Java. What is an exception? An exception is an error condition that changes the normal flow of control in a program Exceptions in Java separates.
Exception Handling in C++. Outline What exceptions are and when to use them Using try, catch and throw to detect, handle and indicate exceptions, respectively.
Exception Handling Outline 23.1 Introduction
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
Exception Handling How to handle the runtime errors.
C# Exceptions 1 CNS 3260 C#.NET Software Development.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Lecture 18B Exception Handling and Richard Gesick.
Exception Handling in C++
16 Exception Handling.
Why exception handling in C++?
Chapter 14: Exception Handling
Exception Handling and
CNS 3260 C# .NET Software Development
Chapter 11—Exceptions Handling Exceptions Throwing Exceptions.
Exceptions Problems in a Java program may cause exceptions or errors representing unusual or invalid processing. An exception is an object that defines.
Part B – Structured Exception Handling
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Fundaments of Game Design
Exception and Event Handling
Presentation transcript:

Dr. Abraham

Exception Any problem that VB or OS could not handle Robust program A program that performs well not only under ordinary conditions but also under unusual conditions that stress its designers' assumptions. Fault tolerant Deal with problems and continue executing

Exception handling Overview Perform a task If the task did not execute correctly (exception thrown) perform error processing Perform next task If program is not fault tolerant the program terminates and prints an error message as given by the operating system.

Exceptions Old days, programmers used code for every possible anticipated errors. Today there are built in handlers This removes the error-handling code from main-line of the program’s execution, improving clarity of the program. You can choose to handle any exceptions There are hierarchy of exceptions. You choose what you want to handle.

Exception handling As soon as an exception is raised all further execution of the methods code is halted and transferred to a catchment area. Catchment area is the catch block between try and end try. Two models exist The resumption model Execution returns to the raise point The termination model

Handling an Error Try Program statements Example place a division by zero Catch avariableName As DivideByZerioException Show the message contained in avariableName.Message End Try

Example see page 582 Division by zero without exception handling Program dies and prints out the STACK TRACE Stack trace includes the exception name (system.dividebyzeroexception) and gives the method where it occoured (main()) In the second error on p 582, “hello” was entered instead of a number. A system.formatexception was thrown.

Catching exceptions in this example Try Result = numerator \denominator Catch aVariableName as formatException Write a message of some sort here Catch aVariableName as DivideByZeroException Write a message of some sort here End Try -make sure to spell exceptions exactly-

Catching Exceptions A try block may have several catch blocks Exception-handling code appears in a catch block May use a parameter to assign the caught error If no parameter is given (i.e. catch without any parameters) will catch all exceptions. Uncaught exception will open the exception assistant within the debug environment.

Finally Block Finally block is guaranteed to execute regardless of whether the try block executes successfully or an exception occurs. In the final block one may place resource release code such as file close, memory de-allocation, etc. Example: Finally If Not (exampleObject Is Nothing) Then exampleObject.Dispose() End if

Model of Exception Handling When problem is detected, an exception is thrown (the point at which error occurred is called a throw point). If the throw point is in the try block, that block is terminated and the program control transfers to the catch block and continues after the catch block. CLR tries to match an appropriate catch block if there are several.

Termination model of exception handling If an exception occurs in a try block, the program control is transferred to the following catch block where the exception parameter’s type matches the thrown exception. Then the control resumes after the last catch block. This is known as resumption model of exception handling or termination model of exception handling. If no exception occur, the program completes the try block and skips all catch blocks and executes the first statement following the try and catch blocks.

An Example program Demonstrated here

.NET exception Hierarchy Class Exception of namespace System is the Base class A derived class from this is the SystemException. An example is out-of-range array index. The systemException throws IndexOutOfRangeException. Other examples: OutofMemoryException, StackOverflowException, etc.