Recent

Author Topic: Lazarus IDE displays the exception message box when Ctrl C on console  (Read 1119 times)

OpenSIMPLY

  • New Member
  • *
  • Posts: 11
When running a console app in Lazarus, sending Ctlr C (SIGINT) causes to the exception message box on Windows.
This happens in both debug and release builds, so as far as I understand it has nothing to do with the debugger (gdb).

This is useful notification, but it would be nice if there was an option to disable this feature, just as language exceptions can be disabled in the project options.

After googling this question and even reporting it as a possible IDE issue, much to my surprise, I didn't find an answer.

Anybody knows?

P.S. The obvious solutions don't work because the IDE probably intercepts the SIGINT handler after the console window is launched (see below).

Code: Pascal  [Select][+][-]
  1. program TestCtrlC;
  2.  
  3. uses
  4.   Windows,
  5.   SysUtils;
  6.  
  7. function CtrlBreakHandler(CtrlBreak: boolean): boolean;
  8. begin
  9.   WriteLn('CtrlBreakHandler');
  10. end;
  11.  
  12. function ConsoleCtrlHandler(dwCtrlType: DWORD): WINBOOL; stdcall;
  13. begin
  14.   WriteLn('ConsoleCtrlHandler');
  15. end;
  16.  
  17. begin
  18.   WriteLn('Press Ctrl C');
  19.  
  20.   // SysSetCtrlBreakHandler(@CtrlBreakHandler);             (* Solution 3 *)
  21.  
  22.   // SetConsoleCtrlHandler(@ConsoleCtrlHandler,true);       (* Solution 2 *)
  23.  
  24.   (*
  25.   ReadLn;
  26.   WriteLn;
  27.   ReadLn;
  28.   *)
  29.  
  30.   try                                                       (* Solution 1 *)
  31.     ReadLn;
  32.     WriteLn;
  33.     ReadLn;
  34.   except
  35.     on e: Exception do
  36.       WriteLn(e.Message);          // ESigQuit expected
  37.   end;
  38.  
  39.   WriteLn;
  40. end.
« Last Edit: December 12, 2023, 11:38:42 am by OpenSIMPLY »

ASerge

  • Hero Member
  • *****
  • Posts: 2481
Re: Lazarus IDE displays the exception message box when Ctrl C on console
« Reply #1 on: December 12, 2023, 05:32:22 pm »
If you are talking about it (screen 1), then use it (screen 2).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12297
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus IDE displays the exception message box when Ctrl C on console
« Reply #2 on: December 12, 2023, 06:19:00 pm »
I did some tests. (I am using Lazarus trunk 3.99 and fpc 3.2.3). Using Windows 10 / 64 bits

The application itself did not open any dialogs for me at all.

When running under GDB, then the IDE would open a dialog about "SigInt".
Using FpDebug this did not happen.

Running outside the IDE, the app also just quit (and never printed the message from the except block).
Also running without except block (and none of the other workaround either), the app still just quit as it should.

 

TinyPortal © 2005-2018