Recent

Author Topic: [SOLVED] How to know if finally is reached because exception?  (Read 4537 times)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 825
    • Lebeau Software
Re: How to know if finally is reached because exception?
« Reply #15 on: December 28, 2018, 10:47:55 pm »
Ehm... in Object Pascal every exception is a descendant of TObject. However not every exception needs to be a descendant of SysUtils.Exception. So ExceptObject will always be assigned if an exception occurred (and has not yet been handled by an exception handler).

My point was, not every possible exception may cause a TObject-derived to be raised.  It depends on the types of system/hardware exceptions the RTL catches and converts to objects.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 825
    • Lebeau Software
Re: [SOLVED] How to know if finally is reached because exception?
« Reply #16 on: December 28, 2018, 10:50:18 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.RunIfYouDare(const WithException: Boolean);
  2. { Let's check with and without a declared object.
  3.   Note: e: Exception is a field of the form }
  4. begin
  5.   if WithException then begin
  6.     e := Exception.Create('You dared!');
  7.     raise e;
  8.   end else
  9.     raise Exception.Create('You (almost) dared!');
  10. end;
  11.  

There is no functional difference between 'e := Exception.Create; raise e;' and 'raise Exception.Create;'.  They do the exact same thing - create an object, and then raise it.  It doesn't matter where the object is stored in memory between the 'Create' and 'raise' statements.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

lucamar

  • Hero Member
  • *****
  • Posts: 3079
Re: [SOLVED] How to know if finally is reached because exception?
« Reply #17 on: December 28, 2018, 11:36:26 pm »
There is no functional difference between 'e := Exception.Create; raise e;' and 'raise Exception.Create;'.  They do the exact same thing - create an object, and then raise it.  It doesn't matter where the object is stored in memory between the 'Create' and 'raise' statements.

Yes, I know. But when I test something (even in this ... stupid? way) I always try to see if there is some internal difference between two apparently equal constructs. I'm not well versed in the intrincacies of compilers, you see. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2262
  • Compiler Developer
Re: How to know if finally is reached because exception?
« Reply #18 on: December 29, 2018, 11:45:26 am »
Ehm... in Object Pascal every exception is a descendant of TObject. However not every exception needs to be a descendant of SysUtils.Exception. So ExceptObject will always be assigned if an exception occurred (and has not yet been handled by an exception handler).

My point was, not every possible exception may cause a TObject-derived to be raised.  It depends on the types of system/hardware exceptions the RTL catches and converts to objects.
And my point is that the RTL always raises an exception object. Look at rtl/inc/system.inc, HandleErrorFrame and rtl/objpas/sysutils/sysutils.inc, RunErrorToExcept.

 

TinyPortal © 2005-2018