Page 1 of 1

Unknown exception when deriving from Exception in C++

Posted: Wed Oct 30, 2019 2:50 pm
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.

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

Posted: Thu Oct 31, 2019 4:38 pm
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?

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

Posted: Mon Nov 04, 2019 2:57 pm
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.

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

Posted: Mon Nov 04, 2019 7:46 pm
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...