Solved

Exceptions, DLL's and Threads

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now