Why exceptions for error handling is so important
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jan 14 09:45:26 PST 2015
On Wednesday, 14 January 2015 at 11:17:52 UTC, Marc Schütz wrote:
> Your claims:
>
> - Exceptions are for "I have no idea what to do about this"
> situations.
> - "exceptions for control flow [...] makes for very
> unreadable/unmaintainable code"
>
> Ola's answer directly addresses these claims and provides a
> counter-example (in the last paragraph), which I happen to
> agree with.
>
> => Not a strawman.
Being precise is important.
The example presented (ie throwing a exception signaling a http
code) is a good one and never contradict what I said.
It is an example "I have no idea what to do about this". The code
throwing the exception is faced with a situation where it cannot
continue (assuming this code is expected to generate a webpage or
something like that) but at the same time, is not in a position
to perform the custom http so it is bailing out. It is signaling
to higher level "I would have liked to return this http code, but
have no idea how to do so and so I'm giving up."
Now I see how you can consider this as a control flow, but it is
vastly different from usual control flow (loops, branches, calls,
...). It is vastly different. You have no idea where you send
your program into. In fact, you may not even be in in the
framework that can make sens of this exception, you have no idea.
Conversely, the framwork that is catching this exception have no
idea where it came from, and it do not care either. It simply
know that the page failed to render and that instead it should
return a specific error code.
More information about the Digitalmars-d
mailing list