Rethrowing Exceptions
Now
that we’ve discussed the framework for building
robust error- and exception-handling capabilities into your
ColdFusion applications, let’s look at a technique
you can use to create more advanced exception-handling systems for
your applications. On occasion, it may be desirable to rethrow an
exception that can’t be handled adequately by a
cfcatch
tag. For example, you may have a
cfcatch
block that catches an error that it
isn’t explicitly designed to handle. In this case,
it’s desirable to rethrow the exception so that a
more qualified error handler can deal with the exception. This can be
accomplished using the cfrethrow
tag. The
cfrethrow
tag is used within a
cfcatch
block to rethrow the active exception
while preserving the cfcatch.Type
and
cfcatch.TagContext
return variables. This lets you
build an additional level of decision making into your
exception-handling routines.
To get a better idea of how the cfrethrow
tag can be used, consider an example in which you want to provide a backup data source to use in the event that a query to your main data source fails. This type of functionality is highly desirable in cases where your entire database is refreshed (i.e., in the case of an extract file) or when you use a file-based database such as MS Access or FoxPro where updating the database often means overwriting the production version with a new version. It is also a good idea when you just want to provide redundancy, as you would in any sort of e-commerce ...
Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.