Article: D Exceptions and C Callbacks

Rene Zwanenburg renezwanenburg at gmail.com
Fri Aug 9 07:08:45 PDT 2013


On Tuesday, 6 August 2013 at 15:05:22 UTC, Mike Parker wrote:
> Shows how I like to deal with throwing exceptions from C 
> callbacks in D. Target audience is beginner-level. Uses GLFW to 
> demonstrate.
>
> http://www.gamedev.net/page/resources/_/technical/general-programming/d-exceptions-and-c-callbacks-r3323

Nice article. A few minor corrections:

- In your second code sample, the D translation of the C code, 
the line
     glfwSetWindowCloseCallback( &onWindowClose );
   should read either
     glfwSetWindowCloseCallback( win, &onWindowClose );
   or
     win.glfwSetWindowCloseCallback( &onWindowClose );
   Maybe point out both are possible, but perhaps this is out of 
the scope of the article.

- When explaining the difference between D Throwable, Exception, 
and Error, you write:
     The latter is analagous to Java's RuntimeException in that
     it is not intended to be caught. It should be thrown to
     indicate an unrecoverable error in the program.
   Java uses Error for unrecoverable errors too. RuntimeExceptions 
are recoverable and meant to be catched. It would be more 
accurate to say D lacks Java's checked exceptions, D exceptions 
are like Java's RuntimeExceptions, and D Errors are like Java 
Errors.


More information about the Digitalmars-d-announce mailing list