?
Solved

Exceptions, DLL's and Threads

Posted on 1997-05-18
4
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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