[fpc-pascal] EControlC exception

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Feb 6 11:36:05 CET 2008


On 06 Feb 2008, at 11:27, Michael Van Canneyt wrote:

>
> You can catch this signal using a signal handler:
>
> PROGRAM ExControlC;
> (* How to capture [Ctrl+C] in Object Pascal.  *)
>
> {$mode objfpc}{$H+}
>
> USES
>   SysUtils,baseunix;
>
> procedure term(sig :longint);cdecl;
>
> begin
>   Writeln('Interrupt caught');
>   Halt;
> end;

Note that in real programs, you should never call writeln (or pretty  
much any other RTL function) from a signal handler, as many routines  
are not re-intrant (and there is no documentation regarding which  
routines are safe to call from signal handlers and which aren't).


Jonas



More information about the fpc-pascal mailing list