Unknown exception when deriving from Exception in C++

delphi package - automated exception handling
Post Reply
Stefaan Brutyn
Posts: 4
Joined: Thu Aug 02, 2007 8:49 am

Unknown exception when deriving from Exception in C++

Post by Stefaan Brutyn »

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.4 KiB) Downloaded 219 times
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

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

Post by madshi »

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?
Stefaan Brutyn
Posts: 4
Joined: Thu Aug 02, 2007 8:49 am

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

Post by Stefaan Brutyn »

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.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

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

Post by madshi »

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...
Post Reply