Solved

Exceptions, DLL's and Threads

Posted on 1997-05-18
4
191 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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