Unknown exception when deriving from Exception in C++

delphi package - automated exception handling

Unknown exception when deriving from Exception in C++

Postby Stefaan Brutyn » Wed Oct 30, 2019 2:50 pm

I'm using c++ builder rio with the clang compiler. I have derived a new exception class in c++ from the delphi Exception class:

Code: Select all
class ETestException : public System::Sysutils::Exception
{
   ...
};


When the new exception is thrown in the application, the bugreport shows
exception class : Unknown
exception message : Unknown.

So the details of the exception are completely lost. This is only when using the clang compiler, with the classic compiler it works correctly.
I have attached a test project.
Attachments
Project.zip
(59.61 KiB) Downloaded 13 times
Stefaan Brutyn
 
Posts: 4
Joined: Thu Aug 02, 2007 8:49 am

Re: Unknown exception when deriving from Exception in C++

Postby madshi » Thu Oct 31, 2019 4:38 pm

Ugh, this could potentially be *very* complicated to fix... :cry: If you register an exception handler (using RegisterExceptionHandler()), does "exceptIntf->ExceptObject" contain a reference to your exception object? Or is it NULL in that situation?
madshi
Site Admin
 
Posts: 10098
Joined: Sun Mar 21, 2004 5:25 pm

Re: Unknown exception when deriving from Exception in C++

Postby Stefaan Brutyn » Mon Nov 04, 2019 2:57 pm

The ExceptObject is NULL in the exception handler.

It's probably caused by a c++ builder bug: AcquireExceptionObject doesn't work for Clang-thrown exceptions. I assume madExcept uses AcquireExceptionObject internally.

When I replace the throw with:
Code: Select all
   try {
      throw ETestException(L"Test");
   } catch (...) {
      TObject* o = AcquireExceptionObject();
      throw;
   }

then the o in the catch is also NULL.
Stefaan Brutyn
 
Posts: 4
Joined: Thu Aug 02, 2007 8:49 am

Re: Unknown exception when deriving from Exception in C++

Postby madshi » Mon Nov 04, 2019 7:46 pm

IIRC I don't use AcquireExceptionObject directly, but I assume that I'm accessing the same underlying APIs or system structures as AcquireExceptionObject, so that would explain why it doesn't work for you.

There's probably not much I can do about this, sadly.

You could try to workaround the issue by providing the exception object directly in a call to madExcept.HandleException(). Since you raise these exceptions yourself, you should have access to the exception object, right? It needs to be the Delphi-style exception class, though. Not sure if/how you can do that from within C++. I'm not that much of a BCB expert...
madshi
Site Admin
 
Posts: 10098
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 11 guests

cron