Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-06

How to avoid Runtime error 231?

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dusan Halicky

I have following test program:

{$mode delphi}
var a,b : variant;
begin
  a := 'foo';
  b := 5;
  writeln(a+b);    // here Runtime Error appear
  // ... other code
end.

But I need to continue to work, even after Runtime Error 231, I've tried try-except and {$I-} but it doesn't help. Thanks

Reply by email

Jonas Maebe
to Dusan Halicky
Dusan Halicky wrote 13 lines
I have following test program: {$mode delphi} var a,b : variant; begin a := 'foo'; b := 5; writeln(a+b); // here Runtime Error appear // ... other code end. But I need to continue to work, even after Runtime Error 231, I've tried try-except

You have to use the sysutils unit if you want run time errors to be converted into exceptions:

{$ifdef fpc}
{$mode delphi}
{$endif}
uses
   SysUtils;
var a,b : variant;
begin
  try
    a := 'foo';
    b := 5;
    writeln(a+b);    // here Runtime Error appear
  except on Exception do
    writeln('caught');
  end;
  writeln('other code');
  // ... other code
end.

Jonas

Reply by email

Dusan Halicky
to Jonas Maebe

Your example doesn't work, it still crash with runtime error:

dvh$ cat pokus2.pas
{$ifdef fpc}
{$mode delphi}
{$endif}
uses
 SysUtils;
var a,b : variant;
begin
 try
  a := 'foo';
  b := 5;
  writeln(a+b);    // here Runtime Error appear
 except on Exception do
  writeln('caught');
 end;
 writeln('other code');
 // ... other code
end.

dvh$ fpc pokus2.pas
Free Pascal Compiler version 2.2.0 [2008/04/01] for i386 Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling pokus2.pas
pokus2.pas(20) Warning: Implicit uses of Variants unit Linking pokus2
19 lines compiled, 0.2 sec
1 warning(s) issued

dvh$ ./pokus2
Runtime error 231 at $080543F4
$080543F4
$0807AF94
$0807904E
$08079BFD
$080556F1
$08089EC1

$

Reply by email