• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 31. Error Handling > Throwing and Catching Your Own Errors

Throwing and Catching Your Own Errors

You can throw custom exceptions whenever your code encounters a situation that should be considered an error within the context of your application, perhaps because it violates some type of business rule. Therefore, custom exceptions give you a way to teach your ColdFusion code to treat certain conditions—which ColdFusion wouldn't be capable of identifying as problematic on its own—as exceptions, just like the built-in exceptions thrown by ColdFusion itself.

Introducing <CFTHROW>

To throw your own custom exceptions, you use the <CFTHROW> tag. The exceptions you raise with <CFTHROW> can be caught with a <CFTRY>/<CFCATCH> block, just like the exceptions ColdFusion throws internally. If your custom exception is not caught (or is caught and then rethrown via the <CFRETHROW> tag), ColdFusion simply displays the text you provide for the MESSAGE and DETAIL attributes in a standard error message.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint