On Tuesday, 6 August 2013 at 17:54:34 UTC, QAston wrote:

There's one thing though. You say than relying on coder's discipline is error prone and I totally agree with that. But your sollution requires coder to remember to wrap those callbacks in try-catches.

Programming always requires a certain amount of discipline. Remembering to release resources when they are no longer needed, properly handling errors, being aware of the constraints of a particular API call. It's all differing degrees. I don't think it's too much trouble to wrap D function calls in try...catch blocks inside a C callback. It's a one-off thing for each callback and something that will likely be on the programmer's mind when a decision is made to implement such a solution. Properly handling arrays in C is an ongoing, full-time thing where it's easy to overlook a mistake now and again. So Id on't really see it as a problem.

Maybe modifying glfwSetWindowCloseCallback and similar functions to only accept nothrow functions is a good idea?

I'm not sure what you mean. That's a C function, which means it doesn't have any concept of D's nothrow. And, actually, the callbacks should be declared as nothrow anyway. Like:

extern( C ) nothrow void function( GLFWwindow* ) glfwWindowCloseCallback;

Any exceptions thrown by functions called inside the callback must be handled, regardless, if you don't want to lose them.

Reply via email to