Exceptions, handling exceptions & message boxes Year 11 Information Technology.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

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.
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.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Exceptions and Exception Handling Message Boxes.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Chapter 3 Variables, Constants, and Calculations
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.
Exceptions CIS 304 Intermediate Java Programming for Business.
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 8 Exception Handling Sections 1-5, 7.
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.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Chapter 3 Variables, Constants, and Calculations Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Variables, Constants, and Calculations
1 Exception Handling Introduction to Exception Handling Exception Handling in PLs –Ada –C++ –Java Sebesta Chapter 14.
 2002 Prentice Hall. All rights reserved. 1 Exception Handling Overview Exception handling –Enable clear, robust and more fault-tolerant programs –Process.
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
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
Chapter 12: Exception Handling
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
© 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Programming with Java Chapter 4 Performing Calculations and Formatting.
Introduction to Visual Basic. Introduction In this chapter, we introduce Visual Basic programming with program code. We demonstrate how to display information.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
VB.Net - Exceptions Copyright © Martin Schray
Visual Basic.NET BASICS Lesson 5 Exponentiation, Order of Operations, and Error Handling.
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.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 3 Variables, Constants and Calculations Programming In Visual Basic.NET.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Variables and Constants Variable Memory locations that hold data that can be changed during project execution Example: a customer’s name Constant Memory.
3-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 9: Completing the Basics. In this chapter, you will learn about: – Exception handling – Exceptions and file checking – The string class – Character.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Error Trapping Exception Catching 1. Syntax & Compile-time  VB – Editor/Compiler Logic and Design  You Runtime  You Types of Errors: 2 When your program.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Murach’s Visual Basic 2008, C7, modified or added© 2008, Mike Murach & Associates, Inc. Slide 1.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
Instructors: Sidra Ehsan Budoor Bawazeer CpCS 206.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Lecture 18B Exception Handling and Richard Gesick.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Lecture 11 Dr. Eng. Ibrahim El-Nahry Exception Handling.
C++ Exceptions.
Chapter 3: Variables, Constants, and Calculations
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Introduction Exception handling Exception Handles errors
Chapter 14: Exception Handling
Variables and Arithmetic Operations
Exception Handling Chapter 9.
Part A – Doing Your Own Input Validation with Simple VB Tools
Brief description on how to navigate within this presentation (ppt)
Part B – Structured Exception Handling
Introduction to Visual Basic
Brief description on how to navigate within this presentation (ppt)
Presentation transcript:

Exceptions, handling exceptions & message boxes Year 11 Information Technology

Main points of chapter 3... Variables Constants Calculations Parse method Arithmetic operations and order of Assignment operators (including short versions) Converting between numeric data types (implicit and explicit) Formatting data for display

Handling Exceptions Issues can occur when performing calculations. The parse methods, Integer.Parse and Decimal.Parse fails if the user enters nonnumeric data or leaves the text box blank. This causes an exception error to occur. Can determine program exceptions by using structured exception handling. These can be caught before they throw a run-time error. Catching exceptions as they happen and writing code to take care of the problems is called exception handling.

To try catch exceptions, enclose any statements that might cause an error in a Try/Catch Block. If an error occurs while the statements in the Try block are executing, program control transfers to the Catch block; if a Finally statement is included, the code in that section executes last, whether or not an exception occurred. (See page 138 for example). You can also define which error occurs (i.e. An error for incorrect input rather than calculation issues). Try/Catch Blocks

The Exception class Each exception is an instance of the Exception class. The properties of this class allow you to determine the code location of the error, the type of error, and the cause. The Message property contains a text message about the error, and the Source property contains the name of the object causing the error. The Stack-Trace property can identify the location in the code where the error occurred. You can include the text message associated with the type of exception by specifying the Message property of the Exception object, as declared by the variable you named on the Catch statement.

ExceptionCaused by FormatExceptionFailure of a numeric conversion, such as Integer.Parse or Decimal.Parse. Usually blank or nonnumeric data. InvalidCastExceptionFailure of a conversion operation. May be caused by loss of significant digits or an illegal conversion. ArithmeticExceptionA calculation error, such as division by zero or overflow of a variable. System.IO.EndOfStreamExceptionFailure of an input or output operation such as reading from a file. OutOfMemoryExceptionNot enough memory to create an object. ExceptionGeneric Common Exception Classes

Handling multiple exceptions To try and catch more than one type of exception, use multiple catch blocks. When an exception occurs, the Catch statements are checked in sequence. The first one with a matching exception type is used.

Displaying messages in message boxes To display a message when a user has entered invalid data, we use message boxes (a pop-up window). You use the Show method of the message box to display the message.

The MessageBox object – general forms More than one way to call the Show method. Very important that the arguments you supply exactly match one of the formats. You cannot reverse, transpose, or leave out any of the arguments. Read page of your programming booklet for an explanation of how the difference sections of the statement effect the appearance of a message box. General structure: – MessageBox.Show ( TextMessage, TitleBarText, MessageBoxButtons, MessageBoxIcon) – E.g. MessageBox.Show ( “Enter numeric data”, “Invalid data entry”, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

Activities What is an exception? List two things that may cause an exception. What does the term ‘exception handling’ refer to? Explain what Try/Catch blocks are and how they work. List three common exceptions and write what causes them. Write an assignment statement for ONE of these exceptions. Explain where Titlebar Text and MessageBoxIcon occur in a message box (use your programming booklets). Draw the example of the message box from Slide 9 as you think it would appear.