Recent

Author Topic: Nested exceptions  (Read 4349 times)

big_M

  • Full Member
  • ***
  • Posts: 104
Nested exceptions
« on: November 12, 2021, 06:57:08 pm »
Just a quick question. I recently bought Marco Cantùs handbook (great book imo), and came across nested exceptions. Is it known if that is coming to fpc at some point?

Btw, are there maybe other differences between delphi and fpc that I need to be aware of? I know of anonymous methods. Anything else?
« Last Edit: November 13, 2021, 01:33:51 am by big_M »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1596
    • Lebeau Software
Re: Nested exceptions
« Reply #1 on: November 12, 2021, 07:16:22 pm »
I recently bought Marco Cantùs handbook (great book imo), and came across nested exceptions. Is it known if that is that coming to fpc at some point?

Are you referring to the Exception.RaiseOuterException() method, and Exception.InnerException property?
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

big_M

  • Full Member
  • ***
  • Posts: 104
Re: Nested exceptions
« Reply #2 on: November 12, 2021, 07:36:17 pm »
Yes. Are there maybe alternatives in fpc?

Thaddy

  • Hero Member
  • *****
  • Posts: 19275
  • Glad to be alive.
Re: Nested exceptions
« Reply #3 on: November 12, 2021, 08:59:43 pm »
Not alternatives, but the same. In Pascal syntax of course. Read The Friendly Manual.
objects are fine constructs. You can even initialize them with constructors.

big_M

  • Full Member
  • ***
  • Posts: 104
Re: Nested exceptions
« Reply #4 on: November 12, 2021, 11:10:23 pm »
Not alternatives, but the same. In Pascal syntax of course. Read The Friendly Manual.

Hm, could you explain? Because I can't find any information on Exception.RaiseOuterException() and the compiler doesn't like it either.

Edit: Here are some examples from the book (see line 110 or 121):
https://github.com/MarcoDelphiBooks/ObjectPascalHandbook104/blob/main/09/AdvancedExcept/ExceptionForm.pas
« Last Edit: November 12, 2021, 11:53:08 pm by big_M »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1596
    • Lebeau Software
Re: Nested exceptions
« Reply #5 on: November 13, 2021, 12:50:53 am »
Hm, could you explain? Because I can't find any information on Exception.RaiseOuterException() and the compiler doesn't like it either.

I don't know what Thaddy is talking about, but InnerException and RaiseOuterException() do not exist in FreePascal at this time, nor do any equivalents that I'm aware of.
« Last Edit: November 13, 2021, 12:52:56 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Thaddy

  • Hero Member
  • *****
  • Posts: 19275
  • Glad to be alive.
Re: Nested exceptions
« Reply #6 on: November 13, 2021, 08:21:44 am »
I don't know what Thaddy is talking about, but InnerException and RaiseOuterException() do not exist in FreePascal at this time, nor do any equivalents that I'm aware of.
Well, the combination of specified exceptions and raise inside of the except part does exactly that....The only thing that is NOT -easlily - possible with this construct as opposed to dynamic languages is to go back to the original.
RaiseInnerException equals a named exception.
IOW you can promote exceptions, but not demote them.

But RaiseouterException is simply raise from inside an except block. Clear?
This is not rocket science. Quite surprised - and with due respect - you did not grasp that.
« Last Edit: November 13, 2021, 08:43:04 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

dbannon

  • Hero Member
  • *****
  • Posts: 3826
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Nested exceptions
« Reply #7 on: November 13, 2021, 12:03:37 pm »
...
This is not rocket science.

No, its not Rocket Science. If it was, thousands of people would die !

Davo
Lazarus 4, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

big_M

  • Full Member
  • ***
  • Posts: 104
Re: Nested exceptions
« Reply #8 on: November 13, 2021, 12:19:42 pm »
The only thing that is NOT -easlily - possible with this construct as opposed to dynamic languages is to go back to the original.

Forgive my maybe naive question, I'm really just learning this stuff, but isn't that the whole point of RaiseOuterException and InnerException? At least that is how I understood the author from the book. I mean, sure I can raise a new exception in the handling block of a previous one and forward every information that I need, but still the original exception will be gone?

Thaddy

  • Hero Member
  • *****
  • Posts: 19275
  • Glad to be alive.
Re: Nested exceptions
« Reply #9 on: November 13, 2021, 01:09:47 pm »
Forgive my maybe naive question, I'm really just learning this stuff, but isn't that the whole point of RaiseOuterException and InnerException? At least that is how I understood the author from the book. I mean, sure I can raise a new exception in the handling block of a previous one and forward every information that I need, but still the original exception will be gone?
No it is not ignored.... You handled it.... If you want to go back to the original exception you need to walk the call stack, like a debugger does. Nobody wants that in real - production - code.
Maybe I should write "touched" instead of "handled" depending on your capabilities.
But the question is relevant. I am merely pulling ears instead of hitting.
« Last Edit: November 13, 2021, 01:21:27 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1596
    • Lebeau Software
Re: Nested exceptions
« Reply #10 on: November 15, 2021, 06:57:28 pm »
Forgive my maybe naive question, I'm really just learning this stuff, but isn't that the whole point of RaiseOuterException and InnerException? At least that is how I understood the author from the book. I mean, sure I can raise a new exception in the handling block of a previous one and forward every information that I need, but still the original exception will be gone?

Yes, exactly.  The whole point of RaiseOuerException() and InnerException is to capture the original Exception and carry it up the call stack inside the new Exception, so that a higher except handler can see not only the new Exception but also the previous Exception(s) to understand (or at least log) the history/original cause of WHY an exception was raised in the first place.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

big_M

  • Full Member
  • ***
  • Posts: 104
Re: Nested exceptions
« Reply #11 on: November 15, 2021, 08:30:44 pm »
Yes, exactly.  The whole point of RaiseOuerException() and InnerException is to capture the original Exception and carry it up the call stack inside the new Exception, so that a higher except handler can see not only the new Exception but also the previous Exception(s) to understand (or at least log) the history/original cause of WHY an exception was raised in the first place.

Thank you! Yes, this is how I understood it.

 

TinyPortal © 2005-2018