Recent

Author Topic: Error: Identifier not found "try"  (Read 8571 times)

beampower

  • Newbie
  • Posts: 6
Error: Identifier not found "try"
« on: July 22, 2017, 05:07:29 am »
I'm using Free Pascal IDE for Win32 for i386.
I'm trying manage some error handling using Try ... Except in Pascal.
An example of code is listed below.
It doesn't even get past the compile step.
I get Error: Identifier not found "try".
What's up?

Code: Pascal  [Select][+][-]
  1. program exception1;
  2.     var
  3.         num1, num2, num3 : Integer;
  4.     begin
  5.         try
  6.             num1 := 0;
  7.             num2 := 1;
  8.             num3 := num2 div num1;
  9.             ShowMessage('1 / 0 = '+IntToStr(num3));
  10.         except
  11.             on E : Exception do
  12.             begin
  13.                 ShowMessage('Exception class name = '+E.ClassName);
  14.                 ShowMessage('Exception message = '+E.Message);
  15.             end;
  16.         end;
  17.     end;




molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Error: Identifier not found "try"
« Reply #1 on: July 22, 2017, 05:28:39 am »
Place {$MODE OBJFPC} or {$MODE DELPHI} beneath your program declaration.

The reason is that by default the compiler will compile in MODE FPC, which does not support exceptions.

More on the subject can be read here in the user's guide.

Edit: Or perhaps even better explained, here in the programmers guide.
« Last Edit: July 22, 2017, 05:55:15 am by molly »

 

TinyPortal © 2005-2018