Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: Exception Handling Tujuan Instruksional Khusus: Mahasiswa dapat.

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.
Pemrograman VisualMinggu …6… Page 1 MINGGU Ke Enam Pemrograman Visual Pokok Bahasan: Module, Class & Methods Tujuan Instruksional Khusus: Mahasiswa dapat.
Pemrograman VisualMinggu …2… Page 1 MINGGU Ke Dua Pemrograman Visual Pokok Bahasan: Console Application Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat.
Pemrograman VisualMinggu …7… Page 1 MINGGU Ke Tujuh Pemrograman Visual Pokok Bahasan: Arrays Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Pemrograman VisualMinggu …3… Page 1 MINGGU Ke Tiga Pemrograman Visual Pokok Bahasan: Class, Objects, Methods and Instance Variable Tujuan Instruksional.
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: File and Stream Tujuan Instruksional Khusus: Mahasiswa dapat.
Error Handling in.NET Exceptions. Error Handling Old way (Win32 API and COM): MyFunction() { error_1 = doSomething(); if (error_1) display error else.
Pemrograman VisualMinggu …4… Page 1 MINGGU Ke Empat Pemrograman Visual Pokok Bahasan: Control Statement I Tujuan Instruksional Khusus: Mahasiswa dapat.
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.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 15 – Exception Handling Outline 15.1 Introduction 15.2 Exception-Handling Overview 15.3 Exception-Handling.
 2006 Pearson Education, Inc. All rights reserved. Exception Handling in C++ CS-2303, C-Term Exception Handling in C++ CS-2303 System Programming.
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.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
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:
 2005 Pearson Education, Inc. All rights reserved Exception Handling.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
C++ Exception Handling
E XCEPTION H ANDLING Chapter 11 C S 442: A DVANCED J AVA P ROGRAMMING.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and 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.
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).
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.
 2009 Pearson Education, Inc. All rights reserved Exception Handling.
 2006 Pearson Education, Inc. All rights reserved Exception Handling.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 9 : Exception Handling King Fahd University of Petroleum & Minerals College of Computer.
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.
 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.
CIS 270—Application Development II Chapter 13—Exception Handling.
C++ Exceptions STL Vector. Example int Quotient (int numer, int denom} { if (denom != 0) return (numer/denom); else //What to do?? }
Pemrograman VisualMinggu …10… Page 1 MINGGU Ke Sepuluh Pemrograman Visual Pokok Bahasan: ADO.NET II Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
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 –
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.
(13-1) Exception Handling in C++ D & D Chapter 17 Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
Unit 4 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 23 - Exception Handling Outline 23.1Introduction.
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.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
C# Exceptions 1 CNS 3260 C#.NET Software Development.
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.
Appendix H Exception Handling: A Deeper Look
Chapter 11 – Exception Handling
Exception Handling in C++
16 Exception Handling.
Debugging and Handling Exceptions
Why exception handling in C++?
Chapter 14: Exception Handling
CNS 3260 C# .NET Software Development
Exception Handling Chapter 9 Edited by JJ.
Part B – Structured Exception Handling
Exception Handling By: Enas Naffar.
Programming in C# Lesson 5. Exceptions..
Chapter 11: Exception Handling
Presentation transcript:

Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: Exception Handling Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan dan mengaplikasikan Exception handling pada Visual Basic 2008 Referensi: Deitel Deitel, Visual Basic 2008 (2009), How to Program, Prentice Hall. Chapter 13

Pemrograman VisualMinggu …12… Page 2 Agenda Exception handling Overview Divide by Zero Without Exception Handling Handling DivideByZeroExceptions and Format Exceptions.NET Exception Hierarchy Exception Properties User-Defined Exception Classes

Pemrograman VisualMinggu …12… Page 3 Exception Handling Overview An exception is an indication of a problem that occurs during a program’s execution. Exception handling enables you to create applications that can resolve (or handle) exception. Intermixing program logic with error handling logic can make programs difficult to read, modify, maintain and debug, especially in large applications. Exception handling enables you to remove error- handling code from the “main line” of the program’s execution, improving program clarity and enhancing modifiability. Visual basic enables you to deal with exception handling easily from the beginning of a project.

Pemrograman VisualMinggu …12… Page 4 Divide by Zero Without Exception Handling An exception is thrown when a method or the CLR detects a problem and is unable to handle it. A stack trace includes the name of the exception in a descriptive message that indicates the problem that occurred and the complete method call stack at the time the exception occurred. Division by zero is not allowed in integer arithmetic. When division by zero occurs in integer arithmetic, a DivideByZeroException is thrown. A FormatException occurs when Convert method ToInt32 receives a string that does not represent a valid integer. See Example figure 13_04

Pemrograman VisualMinggu …12… Page 5 Handling DivideByZeroExceptions and Format Exceptions

Pemrograman VisualMinggu …12… Page 6.NET Exception Hierarchy The Visual basic exception handling mechanism allows objects only of class Exception and its derived classes to be thrown and caught. Class Exception of namespace System is the base class of the.NET Framework Class Library exception class hierarchy. The CLR generates SystemExceptions, which can occur at any point during the execution of the program. Many of these Exceptions can be avoided if applications are coded properly. A benefit of using the exception class hierarchy is that a catch block can catch exceptions of a particular type or because of the is a relationship of inheritance can use a base class type to catch exceptions in a hierarchy of related exception types. A catch block that specifies an exception parameter of type exception can catch all exceptions that derive from exception, because exception is the base class of all exception classes. Using inheritance with exceptions enables an exception handler to catch related exceptions using a concise notation. See Example figure 13_01

Pemrograman VisualMinggu …12… Page 7 Exception Properties Property message of class exception stores the error message associated with an Exception object. Property StackTrace of class Exception contains a string that represents the method call stack. Another exception used frequently by class library programmers is InnerException. Typically, you use this property to “Wrap” exception objects caught in your code so that you then can throw new exception types specific to your libraries. When an exception is thrown but not caught in a particular scope, the method call stack is “unwound” and an attempt is made to catch the exception in the next outer try block—this is known as stack unwinding.. See Example figure 13_05

Pemrograman VisualMinggu …12… Page 8 User-Defined Exception Classes User-defined exception class should derive directly or indirectly from class exception of namespace system. User-defined exceptions should typically extend Exception, have a class name that ends with “Exception” and define a parameterless constructor, a constructor that receives a string argument (the error message), and a constructor that receives a string argument and an exception argument (the error message and the inner exception object). See Example figure 13_06-07

Pemrograman VisualMinggu …12… Page 9 Questions & Answers

Pemrograman VisualMinggu …12… Page 10 Thank You