What is the best way to exit from a dll function when an error is encountered?
I apologize for bringing this up again, but I still have a major problem with it.
Say I have a dll that performs some mathematical parsing and calculations. The calling function is only a single C -linkage wrapper function in the dll. I can anticipate likely errors and program the dll methods to do several things when an anticipated error is encountered. (For now, let's not worry about unanticipated errors).
1 - send an error message to the user application using WM_COPYDATA
2 - throw an exception (assuming the calling app has used the try catch scenario)
3 - try to gracefully recover from the error within the dll and keep on going (jump to some safe place - but how ??)
4 - don't throw an exception from within the dll but halt the program (not very nice - the user won't know what happened)
Previous discussions on the matter have predominantly expressed the opinion that it is a 'bad idea' to throw exceptions from within a dll.
Long ago there was in use setjmp.h and something like
if(setjmp(e_buf)) return -1;
, but I believe this was only for old C applications - I'm not really sure. But at least someone back then recognized the need for getting back to a safe place in a process.
Anyway, I'm throwing (no pun intended) this out again for your thoughts. Your ideas, no matter how far out, will be greatly appreciated.
Last edited by Mike Pliam; October 23rd, 2012 at 09:44 PM.