[fpc-pascal] catch segfaults
Tomas Hajny
XHajT03 at hajny.biz
Thu Mar 14 08:39:01 CET 2013
On Thu, March 14, 2013 01:48, Xiangrong Fang wrote:
> 2013/3/14 Ewald <ewald at yellowcouch.org>
>> Once upon a time, Xiangrong Fang said:
>> > Is it possible to use try...except to catch SIGSEGV?
>> I don't know if it is possible, but how about using fpSignal()? See
>> http://www.freepascal.org/docs-html/rtl/baseunix/fpsignal.html
>>
> The document said it is "deprecated"? Also, I want this to be cross
> platform, not for unix only. The use case is:
The documentation proposes the alternative too (however that is still
platform specific indeed).
> try
> buf := GetMemory(1024);
> size := 10240;
> stream.Read(buf^, size);
> except
> ??
> end;
What about trying it yourself?
{$MODE OBJFPC}
var
P: PChar;
begin
try
WriteLn (P^);
except
WriteLn (0);
end;
end.
D:\TEMP>ppc386 -Mobjfpc t.pas
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling t.pas
t.pas(5,12) Warning: Variable "P" does not seem to be initialized
Linking t.exe
9 lines compiled, 0.5 sec , 26704 bytes code, 1644 bytes data
1 warning(s) issued
D:\TEMP>t.exe
0
Tomas
More information about the fpc-pascal
mailing list