enforce()?

Lutger lutger.blijdestijn at gmail.com
Wed Jun 16 15:55:25 PDT 2010


Simen kjaeraas wrote:

> Lutger <lutger.blijdestijn at gmail.com> wrote:
> 
>> Suppose for example (actually this is from real life) there is an
>> important
>> operation which, as a service, also sends an e-mail notification as part
>> of that
>> operation. It is very bad if the operation fails, but a failed
>> notification is
>> not that bad. What to do in case of a bug with the e-mail notification?
>>
>> 1. crash (gracefully), do not complete the operation.
>> 2. log the error for the devs to look into (or crash) *after* the
>> operation is
>> complete, let the operation go through without the e-mail notification.
>>
>> Option 1 is annoying and prevents people from getting work done due to a
>> 'minor'
>> bug. Option 2 however probably results in this bug either not getting
>> noticed
>> quite early enough or ignored in the face of other issues that always
>> seems to
>> have higher priority. Choosing for option 2 can also lead to bugs being
>> swallowed silently or mistaken for exceptional conditions, which is more
>> dangerous.
>>
>> I don't mean to split hairs, I bet a lot of software has these kind of
>> cases.
> 
> How did you end up with an email system that is so horribly broken that
> it spits Errors instead of Exceptions when things are not quite the way
> it wants them to be?

Not Errors, it is not in D and does not distinguish between Errors and 
Exceptions. It was an example, a (design) question. It's very simple:

sendEmail() 
// possibly die here because something relatively unimportant thing is buggy

vs:

try
{
    sendEmail()
}
catch(BadShitThatCanHappen)
{
    RecoverFromBadShitThatCanHappen() // ok, this is good and according to spec
}
catch(Exception ex)
{
    logError() 
    // now crash? assume we know this must be programmer's fault
}

> If it cannot send the email, it may throw an Exception. If you try and
> pass it a handwritten letter, it should throw an Error.
> 
> Basically, throwing an Exception means 'Your attention please, reactor 5
> has a cooling problem you might want to look at', whereas an Error means
> 'Explosion imminent, get the fuck off outta here!'.
> 

No, an Error means the program has a bug. Programs have thousands of bugs, this 
is not related to how critical it is. An Exception can be way more important to 
fix than a bug. WebServerDownException for example, is often not a bug in the 
code that drives websites, but for sure I will contact the sysadmin before even 
thinking of going back to work. The question is how to proceed after the fact.


More information about the Digitalmars-d mailing list