IS 1181 IS 118 Introduction to Development Tools Chapter 7.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Exceptions & exception handling Use sparingly. Things you can do with exceptions: 1. Define a new exception class. 2. Create an exception instance. 3.
Exceptions Ensuring program reliability. Program correctness The term program correctness refers to a program’s working as advertised; that is, it produces.
Exceptions Don’t Frustrate Your User – Handle Errors KR – CS 1401 Spring 2005 Picture – sysprog.net.
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.
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 By: Thomas Fasciano. What is an Exception?  An error condition that occurs during the execution of a Java Program.
SE-1020 Dr. Mark L. Hornick 1 Exceptions and Exception Handling.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Exception Handling.  What are errors?  What does exception handling allow us to do?  Where are exceptions handled?  What does exception handling facilitate?
Lecture 28 More on Exceptions COMP1681 / SE15 Introduction to Programming.
Exceptions and Exception Handling (continued) Carl Alphonce CSE116.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 8 Exception Handling Sections 1-5, 7.
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.
Chapter 81 Exception Handling Chapter 8. 2 Reminders Project 5 due Oct 10:30 pm Project 3 regrades due by midnight tonight Discussion groups now.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
Handling Errors Introduction to Computing Science and Programming I.
©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.
IS 1181 IS 118 Introduction to Development Tools Chapter 5 Reusing Code.
IS 1181 IS 118 Introduction to Development Tools Week 2.
Introduction to Computer Programming Error Handling.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
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.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
PHP3. PHP File Upload With PHP, it is possible to upload files to the server. Create an Upload-File Form To allow users to upload files from a form can.
PHP 5 OOP By: Ilia Alshanetsky. 1 New Functionality  Support for PPP  Exceptions  Object Iteration  Object Cloning  Interfaces  Autoload  And much.
Handling Exceptions in java. Exception handling blocks try { body-code } catch (exception-classname variable-name) { handler-code }
I NTRODUCTION TO PROGRAMMING Starting Out with Java: From Control Structures through Objects CS 146 Class Notes Fall 10.
Exception. Runtime Error Consider the following program: public class BadArray { public static void main(String[] args) { // Create an array with three.
COMP Exception Handling Yi Hong June 10, 2015.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
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.
CSC 270 – Survey of Programming Languages C++ Lecture 6 – Exceptions.
Storing and Retrieving Data
1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CHAPTER 10 ERROR HANDLING & DEBUGGING JavaScript can be hard to learn. Everyone makes mistakes when writing it.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Exception Handling How to handle the runtime errors.
C# Exceptions 1 CNS 3260 C#.NET Software Development.
PHP Exception Handling How to handle and create user-defined exceptions Mario Peshev Technical Trainer Software University
Martin Kruliš Who is General Failure and why is he reading my disk? by Martin Kruliš (v1.0)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.
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.
Flock in PHP By Chao Liang. Basic Flock Concept What is flock? Abbreviation for file locking Why flock? Data consistency. Prevent file corruption. Different.
Introduction to Exceptions in Java CS201, SW Development Methods.
© 2001 by Ashby M. Woolf Revision 2 Exceptions for Exceptional Circumstances Passing a Problem up the Chain of Command.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
16 Exception Handling.
Java Programming Fifth Edition
Error Handling and Validation
YG - CS170.
Chapter 11—Exceptions Handling Exceptions Throwing Exceptions.
Exception Handling Chapter 9 Edited by JJ.
Exception Handling By: Enas Naffar.
Programming in C# CHAPTER - 7
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Error and Exception Handling
PHP-II.
Presentation transcript:

IS 1181 IS 118 Introduction to Development Tools Chapter 7

IS 1182 Things to Cover Exception Handling  Exception Handling Concepts  Structures Try, throw, catch  The Exception Class  User Defined Exceptions  Exceptions in Bob’s Auto Parts  Other Error handling

IS 1183 Exception Handling Concepts Execute code inside of a TRY block  Try { // code to execute }  Within this code there needs to be a throw throw new Exception (‘message’, code)  And outside the code a catch catch (typehint exception)

IS 1184 Concepts - continued So:  <?php try { // some code throw new Exception(‘A terrible error has occurred’, 42); } catch (Exception $e) { echo ‘Exception ‘. $e->getCode(). ‘; ‘. $e->getMessage(0.’ in ‘. $e->getFile(). ‘ on line ‘.$e->getline(). ‘,br />’; } ?>

IS 1185 Exception class Built-in class to help called Exception  Takes two parameters – message and code getCode() getMessage() getFile() getLine() getTrace() getTraceAsString() _toString()

IS 1186 User Defined Exceptions Extend the base class Exception and add your own  <?php  class fileOpenException extends Exception  {  function __toString()  {  return 'fileOpenException '. $this->getCode() . ': '. $this->getMessage().' '.' in ' . $this->getFile(). ' on line '. $this->getLine() . ' ';  }

IS 1187 User Defined Continued  class fileWriteException extends Exception  {  function __toString()  {  return 'fileWriteException '. $this->getCode() . ': '. $this->getMessage().' '.' in ' . $this->getFile(). ' on line '. $this->getLine() . ' ';  }

IS 1188 User Defined - 3  class fileLockException extends Exception  {  function __toString()  {  return 'fileLockException '. $this->getCode() . ': '. $this->getMessage().' '.' in ' . $this->getFile(). ' on line '. $this->getLine() . ' ';  }  ?>

IS 1189 Bob’s Auto Parts <?php class fileOpenException extends Exception { function __toString() { return 'fileOpenException '. $this->getCode(). ': '. $this->getMessage().' '.' in '. $this->getFile(). ' on line '. $this->getLine(). ' '; }

IS Bob’s Auto Parts - 2 class fileWriteException extends Exception { function __toString() { return 'fileWriteException '. $this->getCode(). ': '. $this->getMessage().' '.' in '. $this->getFile(). ' on line '. $this->getLine(). ' '; }

IS Bob’s Auto Parts - 3 class fileLockException extends Exception { function __toString() { return 'fileLockException '. $this->getCode(). ': '. $this->getMessage().' '.' in '. $this->getFile(). ' on line '. $this->getLine(). ' '; } ?>

IS Where does this go? // open file for appending try { if (!($fp 'ab'))) throw new fileOpenException(); if (!flock($fp, LOCK_EX)) throw new fileLockException(); if (!fwrite($fp, $outputstring, strlen($outputstring))) throw new fileWriteException(); flock($fp, LOCK_UN); fclose($fp); echo ' Order written. '; }

IS Where does it go - 2 catch (fileOpenException $foe) { echo ' Orders file could not be opened. '.'Please contact our webmaster for help. '; } catch (Exception $e) { echo ' Your order could not be processed at this time. '.'Please try again later. '; }

IS Other Error Handling Chapter 25 discusses DEBUGGING  This is outside the scope of this course  BUT, it would be good to look at it