There are a number of things you can do. First, I agree, Exceptions have a
different purpose and meaning, so you should implement a solution that works
for you.
given the idea signature divide(decimal,decimal) decimal
We know that there are reasons that you cannot perform the division, one is
that you cannot divide by zero. You expect an exception to occur in this
condition, and since you can account for it it will not break stability in
the program.
So you can do a couple things to get informative information.
A tried and true method is similar to the dialog result.
divide( decimal, decimal, decimal) mathresult
the first to inputs are the inputs for the calculation the third is the
outbound result of the computation and mathresult is either an enum of
status messages or an object containing informative information.
My other ideas are really variations upon this.
Say you have a more complex calculations to perform, for me it would be
rating an insurance premium.
function compute(policy as Policy) as PolicyRate
end funciton
Here I must pass in the entire policy, loop over each item with coverage,
then over each coverage or coverage group and compute a rate, then sum up
all the rates for each item with coverage, then sum up for the policy.
Should a calculation fail, or we can determine bad values, we pass back
informative help for the user so they may change their selections.
dim pr as PolicyRate = RatingEngine.Compute(policy)
if not pr.status = Success then
'tell the user of their bobo
dim dlg as new PolicyErrorDialog(pr)
dlg.show(me)
else
'Display the computed rates
dim dlg as new RatingWorksheet(pr)
dlg.show(me)
end if
Certainly, I have exception management in my calculation routines and even a
generic handler. I have decision trees wrapped around the known potential
issues and in the event of something unexpected, I make note of it and stop
the calculation. Flow of the application remains constant.
try
catch (calculationExceptions) 'Based on Logic
'Prevent minor calculations, most likely a bad value or unexpected result
catch (databaseExceptions) 'Based on environment
'Prevent lookups for factors and surcharges, Network group must be at it
again.
catch (Exception) 'Who knows
'stops calculation processing for an unexpected reason
end try
<ro**********@talk21.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
>A fair point
However, throwing an exception will terminate processing as something
"couldn't be done". In this case what the user wanted couldn't be
done, so the default value was used in stead, and then the processing
can continue with the next records.
Hope that helps.
Roger