Solved

Exceptions, DLL's and Threads

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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