Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Advertisements

Exceptions Ensuring program reliability. Program correctness The term program correctness refers to a program’s working as advertised; that is, it produces.
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.
Try…Catch…Finally Blocks ( continued ) Generic catch clause –Omit argument list with the catch –Any exception thrown is handled by executing code within.
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.
Exceptions and Exception Handling Carl Alphonce CSE116 March 9, 2007.
Exception Handling Yaodong Bi Exception Handling Java exception handling Try blocks Throwing and re-throwing an exception Catching an.
SE-1020 Dr. Mark L. Hornick 1 More Exception Handling and Throwing Exceptions.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Lesson 16 Exceptions Lesson Exceptions1. Murphy’s Law Anything that can go wrong will go wrong Lesson Exceptions2.
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Understand Error Handling Software Development Fundamentals LESSON 1.4.
By Sam Nasr Nasr Information Systems May 14, 2013.
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.
Exceptions and Exception Handling (continued) Carl Alphonce CSE116.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 8 Exception Handling Sections 1-5, 7.
Slides prepared by Rose Williams, Binghamton University Chapter 9 Exception Handling.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Spring 2005 Chapter 8  Errors and Exceptions Throwable class.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 8 Exception Handling Sections 1-5, 7.
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
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.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
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.
CIS 3301 C# Lesson 13 Interfaces. CIS 3302 Objectives Understand the Purpose of Interfaces. Define an Interface. Use an Interface. Implement Interface.
Java Programming: Guided Learning with Early Objects
Exceptions Handling Exceptionally Sticky Problems.
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.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Introduction to Object-Oriented Programming Lesson 2.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Java Programming: Exceptions1 Exceptions Reference: java.sun.com/docs/books/tutorial/essential/exceptions/
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
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:
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Introduction to Exceptions in Java CS201, SW Development Methods.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
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.
Exceptions in the Java programming language J. W. Rider.
Java Exceptions a quick review….
16 Exception Handling.
Chapter 14: Exception Handling
Exception Handling and
C# Event Processing Model
Exception Handling Chapter 9 Edited by JJ.
Part B – Structured Exception Handling
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Introduction to Programming
Presentation transcript:

Understanding Events and Exceptions Lesson 3

Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand Events and Event Handling in the.NET Framework (1.2) Understand structured exception handling Understand Structured Exception Handling in the.NET Framework (1.3) Understand basic application settings Understand Basic Application Settings (1.1)

Delegates – 1 A delegate is special type that can hold a reference to a method. MyDelegate can hold reference to any method that returns nothing and accepts two string parameters.

Delegates – 2 A delegate variable can refer to a method with the same signature as the delegate type. You can indirectly call the Method1 by using the handler delegate variable:

Events Events are a way for a object to notify other objects when something of interest happens. The object that sends the notification is called as a publisher of the event. The object that receives the notification is called the subscriber of the event.

Events - 2 Events are defined using delegates. EventHandler is a predefined handler, which is commonly used for defining events. EventArgs class and its derived types pass event related data to event subscribers.

Publishing an Event

Subscribing to Events The signature of the event handler method matches the requirements of the event’s delegate.

Structured Exception Handling An exception is an error condition that occurs during the execution of a program. When error occurs, the runtime creates an exception object to represent the error and “throws” it. Unless you “catch” the exception by writing proper exception handling code, the program execution will terminate.

try-catch Place the code that throws exceptions inside a try block Place the code that handles the exceptions inside one or more catch blocks immediately below the try block.

try-catch-finally 1 A try block must have at least a catch block or a finally block associated with it. The finally block is always executed regardless of whether an exception is thrown. The finally block is often used to write clean-up code. If present, the finally block, follows the last catch block.

try-catch-finally 2

try-finally The finally block can immediately follow the try block if no exception handling other than cleanup is needed.

Basic Application Settings Application settings store custom application- specific data. Application settings allows you to change certain program settings at runtime without the need to modify the program’s source code. The settings data is stored as XML in a disk file. For Web applications, you store the application settings in the web.config file. For Windows-based applications, the application settings are specified in an app.config file.

Sample Configuration Data

Accessing Application Configuration Use the ConfigurationManager class to access the settings from the application configuration file. The AppSettings property gets the data from the appSettings section of the configuration file. The ConnectionStrings property gets the data from the connectionStrings section of the configuration file.

Accessing Web Application Configuration Use the WebConfigurationManager class to access the settings from the application configuration file. The AppSettings property gets the data from the appSettings section of the configuration file. The ConnectionStrings property gets the data from the connectionStrings section of the configuration file.

Recap Events and Event Handling Delegates Publishing events Subscribing to events Structured Exception Handling Exception handling The try-catch block The try-catch-finally block The try-finally block Basic Application Settings Application configuration Web application configuration