What is the best way to exit from a dll function when an error is encountered?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: What is the best way to exit from a dll function when an error is encountered?

Threaded View

  1. #1
    Join Date
    May 2002
    Posts
    1,727

    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
    Code:
    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 10:44 PM.
    mpliam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center