A Philosophy of Software Design

Walter Bright newshound2 at digitalmars.com
Sun May 24 04:10:31 UTC 2026


Thanks. This is an interesting general purpose method.

But the book suggests a different approach in the title - define them out of 
existence. I've also thought of various general replacement schemes for exceptions.

The difficulty with exceptions is they are complicated. It's difficult to figure 
out what path the code execution goes through when there are various exceptions. 
The exception paths are also a rich source of bugs because they are untested and 
may never trigger.

Some examples of defining them out of existence:

1. The C Standard says the compiler must support n characters in a string 
literal. Implementing this involves detecting the overflow, issuing an error 
message, and then recovering. A define-out-of-existence approach, which I've 
always used, is just keep mallocing memory until the memory allocator fails - 
and then abort the program with "out of memory". You'll see this in the compiler 
code.

2. Instead of throwing an exception when encountering an invalid code point, the 
unicode handler should substitute in an "invalid character" code point. This 
behaves much like a floating point NaN value.

3. Invalid code nodes are replaced with "Error" nodes. This worked far better 
than I anticipated. No exceptions are thrown. It also behaves like NaN.


More information about the Digitalmars-d mailing list