DMD 1.027 and 2.011 releases

Russell Lewis webmaster at villagersonline.com
Thu Feb 28 08:34:45 PST 2008


eao197 wrote:
> On Thu, 28 Feb 2008 07:27:24 +0300, Russell Lewis 
> <webmaster at villagersonline.com> wrote:
> 
>> I wonder if asserts() should be the exception to nothrow.  Like 
>> eao197, I normally run my programs with assert()s turned on.  But it 
>> would be a shame to lose nothrow because of that.
>>
>> Are assert()s catchable?
> 
> Yes, it is catchable:

(snip)

>> Other than in some sort of weird systems programming context (where 
>> you are running one program inside another), why would you want to 
>> catch them?
> 
> It is not necessary to catch AssertError. Sometimes it is necessary to 
> catch any error. For example, in a HTTP-server you could start 
> processing of a new request and catch different kinds of errors to make 
> appropriate response:

I agree that a web server needs to post an appropriate response.  But if 
an assert() has failed, you don't know if the failure is in your main 
program, in a library, or maybe even in your network code.  In that 
case, you can't really rely on your program to keep working correctly, 
and the only sane solution would be to restart it.

My argument, then, is that you need a metaprogram or "watchdog" (such as 
the init process in *NIX, or maybe just a "web server launcher") which 
manages the server programs and restarts them when they crash.

> There is no difference between some application-logic error, index out 
> of range error, no memory error or AssertError. The request processing 
> failed and the reason must be logged.

 From the web client's or the system administrator's perspective, I 
agree.  The error should be reported to the client, and logged for the 
admin.  But from the internal-consistency-of-the-program perspective, 
these are very different.  An out-of-memory error is a (possibly 
transient) memory issue.  The internal logic of the program is intact. 
Array index out of range might (or might not) be survivable.  But a 
failed assert() means that something is (or might be) deeply wrong with 
the internal logic of the program.  That's not something, IMHO, that you 
ought to try to catch and then forget.

Things which are recoverable should throw Exceptions.  Things which are 
fatal should fail assert()s.


More information about the Digitalmars-d-announce mailing list