Delphi multithreading – AcquireExceptionObject/ReleaseExceptionObject to pass exception from one thread to another thread – via G+ and Stack Overflow
Posted by jpluimers on 2017/02/07
A long time ago, Thomas Mueller (dummzeuch) – Google+ reminded [WayBack] me of this which I required a short while ago:
You can use
AcquireExceptionObject():AcquireExceptionObject returns a pointer to the current exception object and prevents the exception object from being deallocated when the current exception handler exits.
Then you can send the pointer to another thread and if you raise it there it will be freed for you, otherwise you must call
ReleaseExceptionObject()to free it.
After the answer by Remy Lebeau [WayBack] and Remko [WayBack] is a comment [WayBack] by mghie [WayBack] that mentions AsyncCalls.pas that now is available on GitHub [WayBack].
If you have a very old (version <= 5) Delphi or just want to look at how AcquireExceptionObject [WayBack] looks like just look at a similar implementation there [WayBack]. Note that instead of the ReleaseExceptionObject [WayBack] call, AsyncCalls re-raises the exception [WayBack].
–jeroen






Leave a comment