0
votes

I have a Delphi 2010 DLL loaded in a Delphi 2010 app. It works fine for the most of the time. But there are some exceptions that escapes from the DLL (even those that are treated by a try..except block) and my application crash with no error message, no information at all. The exceptions what I am talking about are like AV, not like the exceptions raised by the developer. I have tried loading the DLL with SafeLoadLibrary without luck. I also have the app and DLL source code. I am not posting the DLL or the app source code because I can't, they are copyrighted (I really wish I could).

Is there anything I can do to avoid an internal DLL exception to crash my app?

EDIT

I have no way of not allowing the DLL to raise an exception. It can happens, not all codes are perfect. It may be inevitable that the dll raises an exception, but it should not crash the main app. Imagine, for example, that you are using a third party dll which you have no source code. Its not a good thing that when this dll crashs for some reason your main app get killed. It must have an way of not allowing that to happen.

1
try to replicate the errors in a small program, and post here the code.RBA
I will try, but sometimes they close my app, sometimes they do not.Rafael Colucci
You should have a Try/Except around the body of every single exported function from your DLL.David Heffernan
Rafael, try to use MadExcept or JVCLStack to get the entire 'memory' status when your app crash.RBA
@Rafael I repeat, if you can't catch it, and it brings everything down, then you have no choice but to stop it happening in the first place, whatever it is. Your first task should be to isolate whatever this thing is that is not an exception, but that tears your app down. It sounds like a call to TerminateProcess(), or something similar, to me.David Heffernan

1 Answers

1
votes

What you are asking for is not possible. DLL's share the same memory space as the executing process. As such either can do things to cause the application to crash.

You do have the correct idea, in that your DLL needs to do what it can. It needs to be a good citizen in the application process space.

Some things you can do to be nice.

  • Wrap each exported function with a try/except block and handle the exceptions gracefully.
  • During testing use SafeMM to check for memory issues that you may have not have found otherwise.
  • Make sure your not passing Delphi Managed Types