Nested exceptions lazarus / 62-General ---------------------------------------------------------------------- big_M · 2021-11-12 17:57 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? ---------------------------------------------------------------------- Remy Lebeau · 2021-11-12 18:16 Quote from: big_M on November 12, 2021, 06:57:08 pmI 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? ---------------------------------------------------------------------- big_M · 2021-11-12 18:36 Yes. Are there maybe alternatives in fpc? ---------------------------------------------------------------------- Thaddy · 2021-11-12 19:59 Not alternatives, but the same. In Pascal syntax of course. Read The Friendly Manual. ---------------------------------------------------------------------- big_M · 2021-11-12 22:10 Quote from: Thaddy on November 12, 2021, 08:59:43 pmNot 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 ---------------------------------------------------------------------- Remy Lebeau · 2021-11-12 23:50 Quote from: big_M on November 12, 2021, 11:10:23 pmHm, 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. ---------------------------------------------------------------------- Thaddy · 2021-11-13 07:21 Quote from: Remy Lebeau on November 13, 2021, 12:50:53 amI 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. ---------------------------------------------------------------------- dbannon · 2021-11-13 11:03 Quote from: Thaddy on November 13, 2021, 08:21:44 am... This is not rocket science. No, its not Rocket Science. If it was, thousands of people would die ! Davo ---------------------------------------------------------------------- big_M · 2021-11-13 11:19 Quote from: Thaddy on November 13, 2021, 08:21:44 amThe 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 · 2021-11-13 12:09 Quote from: big_M on November 13, 2021, 12:19:42 pmForgive 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. ---------------------------------------------------------------------- Remy Lebeau · 2021-11-15 17:57 Quote from: big_M on November 13, 2021, 12:19:42 pmForgive 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. ---------------------------------------------------------------------- big_M · 2021-11-15 19:30 Quote from: Remy Lebeau on November 15, 2021, 06:57:28 pmYes, 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.