Handling of Windows Exceptions as signals makes catching them impossible
Original Reporter info from Mantis: Martok @martok
-
Reporter name:
Original Reporter info from Mantis: Martok @martok
- Reporter name:
Description:
The current handling of windows exceptions in rtl\win32\signals.pp (directly converting them to signals and jumping to the relevant handlers) makes it impossible to handle them as language exceptions. This is especially annoing because this means it is impossible to log them using a generic exception handler for later debugging.
Additionally, a lot of information about the cause of the exception is lost since the exception information frame is dropped (i.e. "read/write at address xy, code address pq").
I found 0012974 describing the same symptoms for DLLs, however this bug refers to standalone programs and the solution implemented then seems to be WIN64-specific.
Using signals should be the last resort for all language exceptions that did not get caught by any user code, not the first choice.
Steps to reproduce:
Run this program on 32bit Windows as a console application.
What should happen: except block catches a EAccessViolation and outputs it.
What happens: program terminates with SIGSEGV.
Works as excpected in Delphi 7.
--------------------------------------------
program exce;
{mode objfpc}{
H+}
uses
SysUtils;
procedure CauseException;
var
p: pInteger;
begin
p:= Nil;
IntToStr(p^);
end;
begin
try
Writeln('Before Exception');
CauseException;
Writeln('Exception did not happen');
except
on e: Exception do
WriteLn(e.ClassName, ' ', e.Message);
end;
Writeln('Successfully ate the exception.');
ReadLn;
end.
Mantis conversion info:
- Mantis ID: 24908
- Build: 2.7.1 [2013/08/24] for i386
- Platform: Win32
- Version: 2.7.1
- Monitored by: » Vincent (Vincent Snijders), » @PascalDragon (Sven Barth)