Having done a bit of digging around, it seems that this exception is expected and is the way that a thread returns its exit code when the thread terminates.
Here's how it goes. A call is made to System.ExitDll
which does this:
procedure ExitDll(Context: PInitContext);
var
ResultExitCode: Integer;
begin
Context^ := Context.OuterContext^;
ResultExitCode := ExitCode;
ExitCode := 0;
//raise _TExitDllException.Create(ResultExitCode);
_RaiseExcept(_TExitDllException.Create(ResultExitCode));
end;
That's what raises the exception. The exception is handled in _HandleExitDllException
:
function _HandleExitDllException: Integer;
var
ExceptionObject: TObject;
begin
Result := -1;
ExceptionObject := ExceptObject;
if ExceptionObject is _TExitDllException then
Result := _TExitDllException(ExceptionObject).ExitCode
else
_UnhandledException;
_DoneExcept;
end;
This code read the exit code from the exception and returns that value to the caller. You can't see any code in the RTL that calls _HandleExitDllException
, presumably because that is linked in magically by the compiler/linker.
Essentially this is a false positive from your error reporting software. This exception is part of normal program execution. There is nothing to worry about. Apart from your error reporting code which seems to deficient.