Sutter's ISO C++ Trip Report - The best compliment is when someone else steals your ideas....

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Jul 8 23:31:10 UTC 2018


On Sunday, 8 July 2018 14:55:15 MDT John Carter via Digitalmars-d wrote:
> On Saturday, 7 July 2018 at 01:18:21 UTC, wjoe wrote:
> > But that's not how D works. It throws an Error which can be
> > caught.
> >
> > If people are allowed to do something they assume it's
> > legitimate.
> >
> > It should be a compile time error to catch an Error, but it
> > doesn't even emit a warning and it seems to work well which is
> > probably proof enough for people to assume it's good.
>
> I got myself so tangled up in knots with the equivalent in
> Ruby.... You can "rescue" the base Exception class... which
> initially I did everywhere to try give better error messages...
>
> Which more often than not would result in everything going weird
> and insane instead of useful.
>
> Eventually I replaced _every_ "rescue Exception" with "rescue
> StandardError" and life improved majorly.
>
> Seriously folks, trying to "catch and handle" a programming bug
> leads to the very dark side of life.
>
> Especially in a 'C/C++/D" like language where the exception is
> concrete evidence that the system is _already_ in an undefined
> and unreliable state.

I agree, though I'm increasingly of the opinion that we would have been
better off just printing out the debug information at the call site and then
killing the program with a HLT (or whatever the appropriate instruction
would be) so that a core dump gets generated right there. It makes the
program far more debuggable in situations where the problem is not easily
reproduced, and it avoids the entire issue of whether it's okay to catch
Error or Throwable. What we have instead is a situation where someone can
catch something that they shouldn't be catching (thus putting their program
in an even more invalid state), and when the program exits, we've lost the
program state from the point of the failure.

- Jonathan M Davis





More information about the Digitalmars-d mailing list