Recent

Author Topic: Application exit without showing error message on exception  (Read 766 times)

Fahmy Rofiq

  • Jr. Member
  • **
  • Posts: 80
Application exit without showing error message on exception
« on: September 13, 2021, 11:57:13 am »
Hello,

Testing with new project

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, unit1
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. var
  16.   x, y: Integer;
  17. begin
  18.   x := 0;
  19.   y := 5 div x;    
  20.   RequireDerivedFormResource:=True;
  21.   Application.Scaled:=True;
  22.   Application.Initialize;
  23.   Application.CreateForm(TForm1, Form1);
  24.   Application.Run;
  25. end.
  26.  

Debugger showing error Division by Zero, after click continue application just exit without complain anything.
Lazarus Trunk + FPC Fixes 32bit
Windows 10 x64

Warfley

  • Hero Member
  • *****
  • Posts: 596
Re: Application exit without showing error message on exception
« Reply #1 on: September 13, 2021, 01:25:41 pm »
Yes, on exception the program will check the what the last except block is. As your application doesn't have one, it can't find one and it will simply kill the program.

The LCL does a little trick, by internally handling exceptions within the main/message loop (i.e. in the Application.Run) so exceptions inside an form event called handled by the message loop will result in a message box notification. But exceptions outside the LCLs message loop need to be handled manually

 

TinyPortal © 2005-2018