[fpc-pascal] catch segfaults
Jonas Maebe
jonas.maebe at elis.ugent.be
Thu Mar 14 10:47:36 CET 2013
On 14 Mar 2013, at 01:48, Xiangrong Fang wrote:
> The document said it is "deprecated"? Also, I want this to be cross
> platform, not for unix only. The use case is:
>
> try
> buf := GetMemory(1024);
> size := 10240;
> stream.Read(buf^, size);
> except
> ??
> end;
That use case is a textbook example of why you should never try to
catch and handle access violations, except possibly if you then warn
the user that anything could happen if he continues (including erasing
all files on his hard drive, if he's very unlucky).
An access violation often indicates that memory has been corrupted.
Catching the access violation does not undo the memory corruption, it
just informs you about this fact. If you continue after catching the
exception in the above program, you will be working with corrupted
memory, which means that the behaviour of your program becomes
completely unpredictable afterwards.
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130314/b78bc8d4/attachment.html>
More information about the fpc-pascal
mailing list