Recent

Author Topic: [SOLVED] Exception not Handled  (Read 2176 times)

BenLaz

  • New Member
  • *
  • Posts: 38
[SOLVED] Exception not Handled
« 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
« Last Edit: August 15, 2014, 04:36:24 pm by BenLaz »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7630
Re: Exception not Handled
« Reply #1 on: August 15, 2014, 03:00:56 pm »
Make sure you  USES sysutils.

BenLaz

  • New Member
  • *
  • Posts: 38
Re: Exception not Handled
« Reply #2 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.   

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Exception not Handled
« Reply #3 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

.
« Last Edit: August 15, 2014, 04:24:39 pm by ChrisF »

BenLaz

  • New Member
  • *
  • Posts: 38
Re: Exception not Handled
« Reply #4 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.