'idiomatic' porting of c and or c++ code that does NULL checking

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 27 02:29:11 PDT 2014


On 8/27/2014 2:39 PM, Vladimir Panteleev wrote:
> On Monday, 25 August 2014 at 03:19:09 UTC, Mike Parker wrote:
>> I use Exception for recoverable errors and Error for those that aren't.
>
> Sorry, you're right, that description of Exception/Error is correct. But
> I don't think that SDL initialization is a non-recoverable error. The
> program might want to retry SDL initialization with different
> parameters, and if that code would make it into a library, said library
> might try using a different graphics library or use some other form of
> user interaction.

It is entirely reasonable for someone to decide that failure to init SDL 
is an unrecoverable error, while failure to create a window is not, or 
that both are or neither is. I don't see that any one of the these 
approaches is set in stone, or that it even need be the same from 
project to project.

The way I structure my code in the little rinky-dink projects scattered 
about my hard drive, any failure in initializing required systems (like 
graphics) is an Error, whereas init failure for noncritical systems 
(like audio) is an Exception. The former I let filter to a top-level 
handler where I log them and exit, the latter I catch and respond where 
appropriate. I would very likely take a different approach were I 
developing a library for public consumption so that the user can decide.

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



More information about the Digitalmars-d-learn mailing list