Advanced ColdFusion: Error Handling Mosh Teitelbaum evoch, LLC.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

PHP Form and File Handling
Exception Handling. Background In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist, and code.
Error Handling With Fusebox Presentation By Eron Cohen.
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.
Jerry Lebowitz. Topics  Provides a facility for a systematic object oriented approach to handling runtime errors ◦ Can also handle runtime errors.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
The Web Warrior Guide to Web Design Technologies
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Rossella Lau Lecture 9, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 9: Application with Exception Handling 
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
DT228/3 Web Development JSP: Directives and Scripting elements.
JavaScript, Fourth Edition
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
IT533 Lectures Configuring, Deploying, Tracing and Error Handling.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
JavaScript Form Validation
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
ASP.NET Programming with C# and SQL Server First Edition Chapter 6 Debugging and Error Handling.
Object Oriented Programming
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.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
The Art of Debugging Shlomy Gantz 02/13/01MDCFUG.
Exception Handling MDCFUG 6/12/2007 David Lakein Programmer / Analyst TeraTech Inc.
Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Exceptions Handling Exceptionally Sticky Problems.
Website Development with PHP and MySQL Saving Data.
Chapter 6 Server-side Programming: Java Servlets
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
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.
Dynamic Debug Output and Error Handling in CF5 and CFMX November 12, 2002 By Douglas M. Smith Application Architect for Teratech, Inc.
Creating Databases applications for the Web Basic HTML review, forms Preview: Server side vs client side Flash HW: Review HTML forms and FLASH examples.
CF Pest Control By Shlomy Gantz President, BlueBrick Inc. Presented by Sandra Clark
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
FT228/3 Web Development Error processing. Introduction READ Chapter 9 of Java Server Pages from O’reilly 2 nd Edition Need to be able to 1) Diagnose and.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Exceptions and Assertions Chapter 15 – CSCI 1302.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Error Handling Michael Smith President TeraTech, Inc ColdFusion, Database & VB custom development
Cool CF Debugging Shlomy Gantz 07/29/01CF_ODYSSEY.
Manohar1 Fault Handling Activities covered: 1.Scope 2.Throw 3.Catch 4.Sensor.
C++ Exceptions.
Chapter 14: Exception Handling
Exception Handling Chapter 9.
Exception Handling Chapter 9 Edited by JJ.
Exception Handling.
Error Handling in Java Servlets
Exception Handling.
Presentation transcript:

Advanced ColdFusion: Error Handling Mosh Teitelbaum evoch, LLC

Why Handle Errors? Professional Handling errors prevents users from seeing ugly and unprofessional error messages. Recoverability Handling errors allows you to gracefully recover and/or redirect users to other resources. Auditing Handling errors allows you to be immediately informed of site errors and to log errors in a useful way.

What Are Errors? Unforeseen Errors are results produced by the code that are generally unforeseen, unanticipated, and/or unplanned for by the developer. A Fact Of Life Any sizable amount of code will contain bugs. The larger the codebase, the larger the amount of bugs. Manageable Errors can be managed and can even be used to our advantage.

How Are Errors Handled? Server Application Code Client Error System From the ground up: 1 st – At the code level 2 nd – At the application level 3 rd – At the server level If left unhandled, the user sees the raw (ugly) error message.

Error Classifications ClassificationDescription LogicFaulty design and/or logic within your code. SyntaxSyntactical errors including misspellings, invalid or missing parameters, etc. RuntimeErrors that occur due to runtime conditions (faulty input data, invalid configuration, etc.) ValidationA form of runtime error. Results from server-side form validation. SystemErrors that occur as a result of system problems (database is down, unresponsive remote host, etc.) RequestErrors that occur as a result of invalid requests (404 errors, invalid HTTP headers, etc.)

Logic Errors Logic errors usually do not result in an error message or a thrown exception, but cause the program to malfunction nonetheless. Logic errors are usually only caught through thorough testing. #counter# Example:

Syntax Errors Syntactical errors occur as a result of misspellings, invalid parameters, invalid data types, and other problems with language syntax. These errors can be caught via application-level and/or server-level error handlers. #someQuery.someField# Example:

Runtime Errors Runtime errors, or Exceptions, are those that occur after syntax checking and are a result of some unforeseen condition such as server-side validation errors, data type mismatches, out of scope data, etc. These errors can be caught via code-level, application-level, and/or server-level error handlers. You are too young to enter this website. Example:

Validation Errors Runtime errors that occur when ColdFusion’s server-side form validation catches a problem with submitted form data. These errors can only be caught via application- level error handlers. Example:

System Errors System errors occur as a result of some sort of system (not code) failure including invalidly configured servers, inaccessible databases, unavailable web resources, and file system errors. These errors can be caught via code-level, application-level, and/or server-level error handlers. Example:

Request Errors Request errors occur as a of a client error, not a server or code error. These client errors include requests for invalid resources (404 errors) and invalid HTTP headers. These errors can only be caught via server-wide error handlers. Example:

ColdFusion Error Handling Server-Wide Error Handler Template that is executed whenever an error is not handled at the application or code level. Server-Wide Missing Template Handler Template that is executed whenever ColdFusion cannot find a requested template. CFERROR Allows specification of application-wide error handling templates. CFTRY / CFCATCH / CFTHROW / CFRETHROW Allows for handling of errors at the code level.

Server-Wide Error Handler Templates 1.Click on “Server Settings | Settings” in the ColdFusion Administrator 2.Complete the input fields at the bottom of the page

Allows specification of application-wide error handling templates. Templates have access to a special scope, ERROR, that contains information about the error. AttributeDescription TypeRequired. The type of error that the custom error page handles. "request" or "validation" or "monitor" or "exception" TemplateRequired. The relative path to the custom error page. MailToOptional. The address of the administrator to notify of the error. The value is available to your custom error page in the MailTo property of the error object. ExceptionRequired. Type of exception. Required if type = "exception" or "monitor".

Catches all errors except server-side validation errors Specified template ignores all CFML code – only ERROR variables can be dynamically displayed. ERROR variables do not need to be enclosed by tags Used to catch errors caused by any other application-wide error handlers Allows you to personalize your error message

TYPE="Request" Error Variables VariableDescription BrowserClient’s User-Agent DateTimeDate and time when the error occurred DiagnosticsDetailed error diagnostics GeneratedContentThe content generated before the error occurred HTTPRefererURL from which this page was accessed MailToValue of the MailTo attribute QueryStringURL’s query string RemoteAddressIP Address of the client TemplateTemplate being executed when the error occurred

Catches all server-side validation errors Specified template ignores all CFML code – only ERROR variables can be dynamically displayed. ERROR variables do not need to be enclosed by tags Must be specified in Application.cfm Allows you to personalize your form validation error messages.

TYPE="Validation" Error Variables VariableDescription InvalidFieldsAn unordered list of validation errors that occurred MailToValue of the MailTo attribute ValidationHeaderDefault ColdFusion text used for header of validation error messages ValidationFooterDefault ColdFusion text used for footer of validation error messages

Catches all runtime errors, except server-side validation errors, that are not caught at the code level Like TYPE=“Request” but can contain CFML code Can create new errors/exceptions Can specify multiple such tags to personalize error messages by exception type.

TYPE="Exception" Error Variables VariableDescription DetailValue of the Detail attribute ErrorCodeValue of the ErrorCode attribute ExtendedInfoValue of the ExtendedInfo attribute Same as TYPE=“Request” plus the following:

Executed whenever a runtime error, caught at the code level, occurs. This template is processed and then control returns to the page where the exception occurred. Can contain CFML code Can create new errors/exceptions Used to log exceptions or to perform any other action that should occur whenever an exception is caught and handled.

TYPE="Monitor" Error Variables VariableDescription MessageValue of the Message attribute TypeValue of the Type attribute Same as TYPE=“Exception” plus the following:

Allows for code-level exception handling. Contains code that may cause exceptions and one or more blocks that are used to handle those exceptions. AttributeDescription

Specifies the type of exception that it catches and contains code used to handle the caught exception. Nested within. AttributeDescription TypeOptional. Specifies the type of exception to be handled by the cfcatch block. The following lists basic exception types you can use: Application Database Template Security Object MissingInclude Expression Lock Custom_type Any (default) SearchEngine (new in CFMX)

/ Code that may throw an exception Code that handles specified exception type Code that handles any other exception type

CFCATCH Variables VariableDescription DetailDetailed message about the error ErrorCodeValue of the ErrorCode attribute ExtendedInfoValue of the ExtendedInfo attribute MessageSimple message about the error TypeType of error blocks have access to a special scope, CFCATCH, that contains information about the caught exception. All exception types share the following CFCATCH variables. Other variables are defined only for specific exception types.

VariableDescription DetailOptional. Detailed information about the custom exception ErrorCodeOptional. An error code identifying the custom exception ExtendedInfoOptional. Extended information about the custom exception MessageOptional. A message about the custom exception TypeOptional. A name for the custom exception ObjectOptional. Throws a Java exception. New in CFMX. Allows you to throw custom exception types. This is usually done when consolidating your exception handling in one or more files specifically created for handling exceptions.

Throwing Custom Exception Types If TYPE is not specified, it defaults to “Application” If custom type is a dot-notation series of strings, ColdFusion will try to match the complete string and, if unable to, will keep generalizing the string until it finds a match or runs out of strings. I.e., ColdFusion will search in this order: com.evoch.myException com.evoch com Any This allows for the definition of a rich exception model

Throwing Java Exception Types Before throwing a Java exception, you must first instantiate an instance of a valid Java exception class. For example: <CFOBJECT TYPE=“java“ ACTION=“create“ CLASS=“jException“ NAME=“javaExceptionObject“> Cannot be used with any other attributes of the tag

VariableDescription Allows you to re-throw the current exception from within a CFCATCH block. This is usually done when an exception is caught within a CustomTag or CFC to allow the calling template to catch and handle the exception.

Trick: Accessing ERROR from CFCATCH Normally, the ERROR scope is only available in error handling templates. CFCATCH blocks are limited to the variables in the CFCATCH scope. But, if you specify a in your Application.cfm file, you can access the ERROR scope from your CFCATCH blocks. #Error.Diagnostics#

Resources Macromedia LiveDocs – Exception Handling With CFML – Just about any Ben Forta book on ColdFusion –

Closing Questions? Contact Info Mosh Teitelbaum evoch, LLC Extras ERROR Variables Advanced Exception Types

Extras: ERROR Variables BrowserClient’s User-Agent DateTimeDate and time when the error occurred DetailValue of the Detail attribute DiagnosticsDetailed error diagnostics ErrorCodeValue of the ErrorCode attribute ExtendedInfoValue of the ExtendedInfo attribute GeneratedContentThe content generated before the error occurred HTTPRefererURL from which this page was accessed InvalidFieldsAn unordered list of validation errors that occurred MailToValue of the MailTo attribute MessageValue of the Message attribute QueryStringURL’s query string RemoteAddressIP Address of the client RootCauseJava exception reported by the JVM as the cause of the “root cause” of the exception. New in CFMX TagContextArray of structures containing information for each tag on the stack (currently open tags). TypeValue of the Type attribute ValidationHeaderDefault ColdFusion text used for header of validation error messages ValidationFooterDefault ColdFusion text used for footer of validation error messages

Extras: Advanced Exception Types CFEXECUTE.OutputErrorHTTPFileNotRenderableHTTPRequestURITooLarge CFEXECUTE.TimeoutHTTPForbiddenHTTPResetContent FileExceptionHTTPGatewayTimeoutHTTPSeeOther HTTPAcceptedHTTPGoneHTTPServerError HTTPAuthFailureHTTPMethodNotAllowedHTTPServiceUnavailable HTTPBadGatewayHTTPMovedPermanentlyHTTPSwitchingProtocols HTTPBadRequestHTTPMovedTemporarilyHTTPUnsupportedMediaType HTTPCFHTTPRequestEntityTooLargeHTTPMultipleChoicesHTTPUrlValueNotPassed HTTPCGIValueNotPassedHTTPNoContentHTTPUseProxy HTTPConflictHTTPNonAuthoritativeInfoHTTPVersionNotSupported HTTPContentLengthRequiredHTTPNotAcceptablePOPAuthFailure HTTPContinueHTTPNotFoundPOPConnectionFailure HTTPCookieValueNotPassedHTTPNotImplementedPOPDeleteError HTTPCreatedHTTPNotModifiedRequest.Timeout HTTPFailureHTTPPartialContentSERVLETJRunError HTTPFileInvalidPathHTTPPaymentRequiredHTTPConnectionTimeout HTTPFileNotFoundHTTPPreconditionFailed HTTPFileNotPassedHTTPProxyAuthenticationRequired All advanced exception types are preceded with "COM.Allaire.ColdFusion."