Solved

Exceptions, DLL's and Threads

Posted on 1997-05-18
4
187 Views
Last Modified: 2010-04-06
Hi,

I'm working on an application which raises custom exceptions from inside a DLL. The exceptions are raised both from within the main thread as well as from a second thread (which exists inside the DLL).

Now, when the exception in the 2nd thread is raised, the default handler pops up behind all other windows!!

When the exception in the main thread (ie - inside the call to the DLL), the handler does not display and the message passed to the exception's Create constructor does not get displayed. Further, after closing the exception handler dialog, the application does not terminate!

If I wrap the DLL call in a try/except block, then re-raise the exception - there is no change. I can of course call Application.Terminate in my handler - but why should I have to?? And I can't do that with the exception in the 2nd thread because the call to the DLL returns before the exception gets raised!

One final puzzle - if I replace the default exception handler (ie: Application.OnException := My Handler), it NEVER gets called when a DLL exception is raised!!!

I'm obviously missing something pretty basic here .... any ideas?

Reply via email please, as I don't frequent this site

Best Regards,

Paul
0
Comment
Question by:sonique
  • 2
4 Comments
 
LVL 3

Expert Comment

by:sperling
ID: 1336438
There's only one simple solution to this.... Change your DLL to avoid exceptions, and rather report errors back to the application by e.g. a callback or some private messages.

Due to Delphis method of storing RTTI (=Run-Time Type Information) in the apps/dlls you create, an exception raised in the DLL will not be of the same type as the same exception raised in the app, and an On Exception statement in the app would not catch an exception raised in the DLL.

The reason your Application.OnException ain't called, is because the DLL doesn't know about the application object in your app, and it'll use the ExceptProc procedure pointer for processing exceptions.

I'd suggest you replaced the ExceptProc pointer with a pointer to your own error-handling method, which preferrably should send a message to the application indicating which exception occurred. Then, your applications message handler could recreate and raise the exception, allowing for normal processing of the error.

Regards,

Erik.
0
 
LVL 3

Accepted Solution

by:
mheacock earned 100 total points
ID: 1336439
You should invite SPERLING to answer this so that you can grade
him.  His comment was a pretty good answer.
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1336440
oops.
0
 

Author Comment

by:sonique
ID: 1336441
How do I get back to SPERLING's reply so that I can grade it?
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question