Martin Kruliš Who is General Failure and why is he reading my disk? 19. 3. 2015 by Martin Kruliš (v1.0)1.

Slides:



Advertisements
Similar presentations
Exceptions Chapter Throwing and Catching Exceptions When a program runs into a problem that it cannot handle, it throws an exception. Exceptions.
Advertisements

Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 16 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.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
CSIS 123A Lecture 11 Exception Handling. Introduction  Typical approach to development:  Write programs assuming things go as planned  Get ‘core’ working.
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.
Exception Handling Yaodong Bi Exception Handling Java exception handling Try blocks Throwing and re-throwing an exception Catching an.
Chapter 8Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 8 l Basic Exception Handling »the mechanics of exceptions l.
Exception Handling 1 CISC6795, Spring Introduction 2 Exception – an indication of a problem that occurs during a program’s execution, for examples:
Chapter 12 By Tony Gaddis Modified by Elizabeth Adams Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
Error Handling with Exceptions Concepts C and other earlier languages often had multiple error-handling schemes, and these were generally established.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Exception Handling. Introduction One benefit of C++ over C is its exception handling system. An exception is a situation in which a program has an unexpected.
Exceptions and Exception Handling Carl Alphonce CSE116.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 16 Exception Handling.
Exception Handling. Introduction An exception is an abnormal condition that arises in a code sequence at run time. In computer languages that do not support.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
© Copyright Eliyahu Brutman Exceptions. © Copyright Eliyahu Brutman Exceptions and Design Patterns - 2 Introduction to Exception Handling Definition:
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Lecture 8 : PHP Errors & Exceptions UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
Kyle MacLachlan.  Used To Format a Date/Time  Syntax: › date(format,timestamp)  format: Required, specifies format  timestamp:Optional, specifies.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
What is an exception? An exception is: – an event that interrupts the normal processing of the program. –an error condition that violates the semantic.
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
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Slides Credit Umair Javed LUMS Web Application Development.
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 Workshop ‹#› PHP Error Handling. PHP Workshop ‹#› Types There are 12 unique error types, which can be grouped into 3 main categories: Informational.
Handling Exceptions in java. Exception handling blocks try { body-code } catch (exception-classname variable-name) { handler-code }
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 –
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Exceptions cs1043. Program Exceptions When a program detects an error, what should it do? – Nothing, simply allow the program to fail. – Implement a course.
Exception Handling Programmers must deal with errors and exceptional situations: User input errors Device errors Empty disk space, no memory Component.
Computer Programming with JAVA Chapter 8. Exception Handling Basic Exception Handling the mechanics of exceptions Defining and Using Exceptions some "simple"
PHP Error Handling Section :I Source: 1.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
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-Handling Fundamentals  A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
PHP: Beyond the Basics. Beyond the Basics Error Reporting Exception Handling Variable Interpolation Cookies Headers Image Manipulation Including/Organizing.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
PHP Exception Handling How to handle and create user-defined exceptions Mario Peshev Technical Trainer Software University
CSC241 Object-Oriented Programming (OOP) Lecture No. 22.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Martin Kruliš by Martin Kruliš (v1.0)1.
PHP Best Practices and Living Standards
Exception Handling in C++
CMSC202 Computer Science II for Majors Lecture 16 – Exceptions
EXCEPTION HANDLING IN C++
EXCEPTION HANDLING.
Chapter 14: Exception Handling
Exception Handling Chapter 9.
Exceptions Problems in a Java program may cause exceptions or errors representing unusual or invalid processing. An exception is an object that defines.
Exception Handling Chapter 9 Edited by JJ.
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
PHP Standardization and A Few Loose Ends
Presentation transcript:

Martin Kruliš Who is General Failure and why is he reading my disk? by Martin Kruliš (v1.0)1

 Concept of Exceptions ◦ Similar to other object languages  Exceptions are thrown and caught ( throw, catch )  Exception is an object of class Exception or derived class ◦ Used for reporting errors  Especially from deeply nested code ◦ Note that …  Uncaught exception causes Fatal Error  Destructors should not throw exceptions  Throwing-catching process is somewhat slow by Martin Kruliš (v1.0)2

 Try-catch Blocks ◦ Exception-safe code is wrapped in try block ◦ First matching catch block handles the exception  Exception is matched by its class try {... Code that may throw an exception... } catch (MyException $e) {... My exception handler... } catch (Exception $e) {... Generic exception handler... } by Martin Kruliš (v1.0)3

 Throwing Exceptions ◦ Keyword throw followed by the exception object throw new Exception('Error …'); ◦ It can be used inside catch-block to re-throw already caught exception try {... } catch (MyException $e) {... Partial exception handling... throw $e; // re-throwing exception } by Martin Kruliš (v1.0)4

 Creating Custom Exceptions ◦ Exception class is derived from Exception ◦ Derived classes need not to override any methods  If the constructor is overridden, parent constructor must be invoked  It is recommended to redefine __toString() ◦ When to customize…  To distinguish a new error type  To add additional data to the exception object by Martin Kruliš (v1.0)5

 Internal Errors ◦ Should not be displayed to the user  User cannot understand them, nor counteract them  Potential security breach ◦ Save them for admin (log, , …)  Error Control Operator ◦ prepended to an expression ◦ All error messages from the expression are ignored ◦ Suitable for specific local solutions only $data or die('Error…'); by Martin Kruliš (v1.0)6

 Error Levels ◦ Define the severity of the error  E_ERROR – fatal errors, terminate the script  E_WARNING – severe errors, but recoverable  E_NOTICE – unusual situations (possible error)  E_USER_xxx – user level error, warning, or notice  E_STRICT – suggestion for improvement ◦ The log can filter selected error levels  Controlled in php.ini or by error_reporting() ◦ User errors can be triggered manually  trigger_error() by Martin Kruliš (v1.0)7

 Setting Up Error Handling ◦ set_error_handler()  Sets a callback that handles runtime errors  Except for Fatal Errors  Can yield handling back to default control  By returning false from the callback function  Default control acts according to php.ini settings ◦ set_exception_handler()  Sets generic handler for uncaught exceptions ◦ restore_error_handler(), restore_exception_handler()  Restore original error handling control by Martin Kruliš (v1.0)8

 Information about Errors ◦ The handling callback gets error level and position ◦ debug_backtrace() – retrieves current call stack ◦ debug_print_backtrace() – prints call stack ◦ Might be wise to log $_GET, $_POST, $_COOKIES, …  PHP Supported Error Logging ◦ error_log() – logs error internally ◦ Error message can be written to the web server log, sent as , or written to a file or a TCP channel by Martin Kruliš (v1.0)9 Example

by Martin Kruliš (v1.0)10