Author Topic: throw exception  (Read 537 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
throw exception
« on: February 27, 2008, 08:27:43 pm »
I did a little Googleing without much luck looking to see if its possible to throw an exception.

For example

Code: [Select]
procedure Lollypop(flavor: string);
begin
  if ((flavor = 'bannana') or (flavor = 'berry')) then begin
    WriteLn('Good job!');
  end else begin
    throw Exception('Not available');
  end;
end;

procedure ActivateServer();
begin
  try
    Lollypop('strawberry');
  except
    WriteLn('Bad mojo: ' + Exception); //Exception: string; being the exception
  end;
end;
Something like that;

I was also wondering if it were possible to check what the actual error is in an exception.

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: throw exception
« Reply #1 on: February 27, 2008, 11:51:40 pm »
Code: [Select]
raise Exception.Create('uhoh, spaghetti-o');

But I'm not sure if it's possible to actually do this inside of the scripting engine.

Technically, different exceptions should be created by creating a class that inherits from Exception, such as ETooMuchSauce. Again, not sure if this is possible from with the scripting engine.