Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a solution for my own exception types.</p> <p>Baiscly I added 2 virtual methods to all my exception types.</p> <ul> <li>virtual Base* Clone(); clones the exception and returns a new one on the heap. This gets around the fact that the origenall one is destroyed when leaving the catch block.</li> <li>virtual void ThrowAndDelete(); this makes a local copy of the heap allocated exception object, deletes the heap one (to prevent memory leaks) and then throws the stack copy. This has the advantage of throwing as the most derived type.</li> </ul> <p>This means I can now simply do:</p> <pre><code>void SendCallback(HWND hwnd, boost::function&lt;void()&gt; call) { fllib::exception::Base *except_ptr = (fllib::exception::Base*)SendMessage(hwnd, WM_CALLBACK, (unsigned)&amp;call, SEND); if(except_ptr) except_ptr-&gt;ThrowAndDelete(); } LRESULT CALLBACK HookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { //check for our custom message if(msg == WM_CALLBACK) { if(lParam == POST) { ... } else { boost::function&lt;void()&gt; *call = (boost::function&lt;void()&gt;*)wParam; try { (*call)(); } catch(fllib::exception::Base &amp;except) { return (unsigned)except.Clone(); } return 0; } } else { ... } } </code></pre> <p>I'm not sure what to do about the std:: and boost:: varity of exceptions since they dont seem to have mtheods to the effect of the above... however 95%+ of the exceptions that are likly not to be handled before hand are my own classes, and those that are not are almost certainly going to go unhandled anyway...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload