Lazarus

Free Pascal => General => Topic started by: BenLaz on August 15, 2014, 02:55:59 pm

Title: [SOLVED] Exception not Handled
Post by: BenLaz on August 15, 2014, 02:55:59 pm
Hello,

I've a strange comportment easily reproductible :

that code doesn't catch the exception and the application stop working

var
  r1 : Real;
begin
  try
    r1 := r1 / 0;
  except
    Beep;
  end;
end.   

Does any one have any idea ?

Ps : I use FPC 2.6.4 and Lazarus from svn trunc
Title: Re: Exception not Handled
Post by: marcov on August 15, 2014, 03:00:56 pm
Make sure you  USES sysutils.
Title: Re: Exception not Handled
Post by: BenLaz on August 15, 2014, 03:05:58 pm
It's the case either in my program and in the simple test program i made.

Here it is :

program Bug;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, sysutils;

var
  r1 : Real;
begin
  r1 := 1;
  try
    r1 := r1 / 0;
  except
    Beep;
  end;
end.   
Title: Re: Exception not Handled
Post by: ChrisF on August 15, 2014, 04:21:10 pm
I guess you're trying to run your program inside the Lazarus IDE, aren't you ?

If it's the case, the most simple way to correct it is to run your program outside the IDE.

There are already some posts about this behavior (i.e. exceptions handling when running inside or outside the IDE ) in this forum.

** Edit ** One of these discussions:
http://forum.lazarus.freepascal.org/index.php/topic,24743.0.html

.
Title: Re: Exception not Handled
Post by: BenLaz on August 15, 2014, 04:29:47 pm
Thank you very much for your answer,

You're right, when running outside of the debugger it just works fine. 
TinyPortal © 2005-2018