Exception Handling  To use Try blocks to delimit code in which exceptions might occur.  To use Catch blocks to specify exception handlers.  To use the.

Slides:



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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
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.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Review Linked list: Doubly linked list, insertback, insertbefore Remove Search.
Exception Handling Handling an unexpected behaviour Unit - 08.
 2006 Pearson Education, Inc. All rights reserved. Exception Handling in C++ CS-2303, C-Term Exception Handling in C++ CS-2303 System Programming.
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.
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.
Jerry Lebowitz. Topics  Provides a facility for a systematic object oriented approach to handling runtime errors ◦ Can also handle runtime errors.
Exceptions Briana B. Morrison CSE 1302C Spring 2010.
Exception Handling 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Understand Error Handling Software Development Fundamentals LESSON 1.4.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
Exceptions Used to signal errors or unexpected situations to calling code Should not be used for problems that can be dealt with reasonably within local.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
 2002 Prentice Hall. All rights reserved Exception-Handling Overview Exception handling –improves program clarity and modifiability by removing.
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
 2006 Pearson Education, Inc. All rights reserved 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.
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.
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.
Object Oriented Programming
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
CIS 270—Application Development II Chapter 13—Exception Handling.
1 CSC241: Object Oriented Programming Lecture No 27.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
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
COMP Exception Handling Yi Hong June 10, 2015.
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 –
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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.
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.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
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.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
Exception Handling. VB.NET has an inbuilt class that deals with errors. The Class is called Exception. When an exception error is found, an Exception.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Lecture 18B Exception Handling and Richard Gesick.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Appendix H Exception Handling: A Deeper Look
Exception Handling in C++
16 Exception Handling.
Exception Handling.
Chapter 14: Exception Handling
Exception Handling and
CNS 3260 C# .NET Software Development
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.
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Fundaments of Game Design
Chapter 11: Exception Handling
Exception Handling.
Presentation transcript:

Exception Handling  To use Try blocks to delimit code in which exceptions might occur.  To use Catch blocks to specify exception handlers.  To use the Finally block to release resources.

Uncaught exception Program mostly terminates when there is an uncaught exception ► If debugging in Visual Studio, application pauses and Exception Assistant appears indicating where the exception occurred the exception occurred

Dim n1, n2, r As Integer n1 = num1.Text n1 = num1.Text n2 = num2.Text n2 = num2.Text r = n1 / n2 r = n1 / n2 MessageBox.Show(r) MessageBox.Show(r) Take and assign inputs from user

Fig | Exception Assistant.

► Error Handling is an essential part of any good code. ► Exception  An indication of a problem that occurs during a program ’ s execution  System.Exception is the base class for all exceptions  The coding structure VB.NET uses to deal with such Exceptions is called the Try … Catch structure.

Syntax Try …. Catch Try [ try statements ] Catch ExceptionVariable As ExceptionType [ catch statements ] ‘ Additional Catch block Finally [ finally statements ] End Try

Try Block ► Means “ Try to execute this code “ ► Encloses code that might throw an exception and the code that should not execute if an exception occurs ► Corresponding End Try ► There must be at least one Catch block and/or Finally block immediately after the Try block

Catch Block ► Means "Catch any errors here “ ► Catches and handles an exception  Begins with keyword Catch  Specifies an identifier and exception type ► Example: Catch e As Exception  Executes when exception of proper type matches

Finally Block ► Programs that obtain certain resources must return them explicitly to avoid resource leaks ► Finally block  Optional in a Try statement  Placed after the last Catch block (if there is one)  Executes whether or not an exception is thrown in the corresponding Try block or any of its corresponding Catch blocks  Generally we use it to close an opened file or connection

Termination Model of Exception Handling ► When an exception occurs:  Try block terminates immediately  Program control transfers to first matching Catch block (other Catch block are ignored) ► After exception is handled:  Termination model of exception handling ► Program control does not return to the throw point because the Try block has expired ► Flow of control proceeds to the first statement after the last Catch block  Resumption model of exception handling ► Program control resumes just after throw point

Try n1 = num1.Text n1 = num1.Text n2 = num2.Text n2 = num2.Text r = n1 / n2 r = n1 / n2 MessageBox.Show(r) MessageBox.Show(r) Catch ex As Exception MessageBox.Show(ex.Message) MessageBox.Show(ex.Message) End Try

DivideByZeroTest

► Delimit تحصر او تحدد ► Release يحرر ► Resources المصادر ► Uncaught exception غير مسك استثناء ► Pauses مؤقتا ► Exception Assistant استثناء مساعد ► Essential ضروري ► obtain certain الحصول على بعض ► Termination Model of Exception Handling إنهاء النموذجي لمعالجة استثناء ► Program control transfers to first matching Catch block (other Catch block are ignored)

► نقل برنامج لمراقبة مطابقة أول كتلة الصيد ► Program control does not return to the throw point because the Try block has expired ► مراقبة البرنامج لا عودة الى رمي النقطة لأن حاول عرقلة قد انتهت صلاحيتها ► Resumption model of exception handling فرضية نموذج لمعالجة الاستثناء ► Program control resumes just after throw point ► يستأنف برنامج مراقبة فقط بعد رمي نقطة ► resumes يواصل