Databases Reference
In-Depth Information
The new version of the
FulfillButton_Click
event handler wraps a
try/catch
block
around the
FulfillOrder
and
SaveChanges
method calls, which could throw validation
exceptions. The
catch
block intercepts all exceptions and passes them to the
HandleException
method of the
UnleashedValidator
(defined at the top of the page
in Listing 9.3). If the
HandleException
method returns
false
, the code re-throws the
exception.
As discussed in Chapter 8, the
UnleashedValidator
class inherits from the built-in
DynamicValidator
and extends error handling to support
AggregateException
. The
HandleException
method receives an
Exception
object as a parameter, iterates over all
UnleashedValidator
controls on the page, including those in field templates, and
attempts to handle the exception by passing it to each validator's
ValidateException
method. The
HandleException
returns
true
if one or more validators on the page were
able to handle the exception by setting their
ValidationException
properties. For
complete details, please refer to the
UnleashedValidator
source code in the
Unleashed.DynamicData
project accompanying the topic.
Figure 9.8 shows an example of an error message displayed because of the
ValidationException
thrown in the
FulfillOrder
business rule method.
FIGURE 9.8
Validation error from calling a business rule method.