exceptions vs error codes

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 11 21:10:56 PDT 2016


On Mon, 11 Jul 2016 06:13:00 -0700, Walter Bright wrote:

> On 7/9/2016 8:02 PM, Superstar64 wrote:
>> Would it be possible and a good idea to have a language feature that
>> allows some exceptions to use error code code generation.
> 
> If you want to return an error code, return an error code. No language
> feature is required.

I think the intent is to tell the compiler: the error case is very 
common, so make that case faster at the expense of the happy path.

Which is fine in theory, but probably not worth the effort, and it isn't 
really the greatest usecase for exceptions in general. If errors are so 
common, you probably want to impress that on the programmer with an 
explicit status code.

For my part, I tend to follow the C# pattern of `foo` and `tryFoo`. I'm 
just writing a library. You can tell me whether this piece of data is 
trusted to be correct or not.


More information about the Digitalmars-d mailing list