RejectedSoftware Forums

Sign up

Error/Exception handling

Hello,

I've been working on a small vibe.d app and I'm wondering what the proper way to handle exceptions in a vibe.d application. I'm asking because I hit an error accessing fields in a std.json JSONValue object whenever the field doesn't exist. Before I created code to work around that (e.g. if it doesn't exist, provide a default value), whenever this would happen the server would crash and I get the following message "Error: Program exited with code -11". I tried putting a try/catch block in the function that the router uses, but for some reason the error/exception is not caught.

I would really like to know how to do this properly because I can't have the server crashing due to something stupid.

I don't know if this matters, but this is being done in the "response" portion of a requestHTTP call. I'm retrieving data from a RESTful data store before returning it semi-transformed to the requesting client.

Re: Error/Exception handling

I suppose your OS is Linux, and you have problem with null pointer. It is not vibe problem, please refer to

http://forum.dlang.org/thread/lg18lj$31bl$1@digitalmars.com

in short you should add:

import etc.linux.memoryerror;
registerMemoryErrorHandler();

Re: Error/Exception handling

On Tue, 15 Apr 2014 06:42:57 GMT, Nikolay Tolstokulakov wrote:

I suppose your OS is Linux, and you have problem with null pointer. It is not vibe problem, please refer to

http://forum.dlang.org/thread/lg18lj$31bl$1@digitalmars.com

in short you should add:

import etc.linux.memoryerror;
registerMemoryErrorHandler();

I wouldn't recommend using it in production code, this module is not widely advertised for a reason : hacky implementation which is not strictly POSIX-compliant. It is helpful for debug builds but to fix actual issue I'd recommend to find origin of null dereference and fix that instead. In general I don't think JSON module should create a null dereference within any normal workflow and if it happens, it should be filed as a bug.

Re: Error/Exception handling

On Tue, 15 Apr 2014 10:30:26 GMT, Dicebot wrote:

On Tue, 15 Apr 2014 06:42:57 GMT, Nikolay Tolstokulakov wrote:

I suppose your OS is Linux, and you have problem with null pointer. It is not vibe problem, please refer to

http://forum.dlang.org/thread/lg18lj$31bl$1@digitalmars.com

in short you should add:

import etc.linux.memoryerror;
registerMemoryErrorHandler();

I wouldn't recommend using it in production code, this module is not widely advertised for a reason : hacky implementation which is not strictly POSIX-compliant. It is helpful for debug builds but to fix actual issue I'd recommend to find origin of null dereference and fix that instead. In general I don't think JSON module should create a null dereference within any normal workflow and if it happens, it should be filed as a bug.

Thanks for the info. Yes, I am on Linux and I'm guessing it's a null pointer issue (No error message). I guess to go back to my original question, it sounds like the issue isn't how I'm handling errors, it's a problem with the std.json library that's causing the program to exit, correct? If so, I'll dig into this further.

Re: Error/Exception handling

On Tue, 15 Apr 2014 13:05:45 GMT, Casey wrote:

Thanks for the info. Yes, I am on Linux and I'm guessing it's a null pointer issue (No error message). I guess to go back to my original question, it sounds like the issue isn't how I'm handling errors, it's a problem with the std.json library that's causing the program to exit, correct? If so, I'll dig into this further.

Yes, in D null pointer dereference always indicates a bug - either in library or application itself, it is not a part of normal error / exception handling.