Learncfinaweek 1 5

Page 295

function onError( any Exception, string EventName ) {

include 'sorry.cfm';

var errorEmail = new mail();

errorEmail.setTo('you@domain.com'); errorEmail.setFrom('system@domain.com');

errorEmail.setSubject('An Error has Occured');

errorEmail.setBody('

Message: #arguments.exception.message# <br />

Details: #arguments.exception.detail# <br />

Type: #arguments.exception.type# <br />

'); errorEmail.setType('html'); errorEmail.send(); } 6. Open up the /www/throwError.cfm file in your browser. You should now see a 'sorry' page. 7. Open up your ColdFusion Administrator and login. The URL for the ColdFusion Administrator is most likely http://localhost:8500/CFIDE/administrator/. 8. Click on 'Mail' under Server Settings. 9. Click on the 'View Undeliverable Mail'. 10. The first item in the list should be your error email. Review the contents of the email that is sent when an email is thrown. 11. Open up the /www/throwError.cfm file in your code editor. 12. Change the contents of the file to the following code:

<cfdump value="2" /> 13. Open up the /www/throwError.cfm file in your browser and notice that an error is thrown. onError does not catch tag syntax errors. For that, we must rely on the site-wide error handler. 14. Create a new file called sitewideErrorHandler.cfm in the / folder. 15. Open the /sitewideErrorHandler.cfm file in your code editor. 16. Add the following line of text to the file: Learn CF in a Week - Week 1 - Error Handling and Debugging

Page 287


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.