You could try registering an exit handler function in main() via atexit(3) or on_exit(3) and breaking in there and viewing the stack trace.
As lee pointed out above, this error code is probably not being thrown by any code you wrote, else you'd recognize it. Most likely, the choke is due to some library or framework you're linked into. If you have no idea where, one way to find out is to run your program under some tracing utility (on linux I use ltrace/strace for this all the time). On Darwin/OSX there's dtrace and dtruss at the command line, and the Instruments GUI in the /Developer/Tools tree.