Program logic bugs vs input/environmental errors
Bruno Medeiros via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 1 06:44:27 PDT 2014
On 28/09/2014 00:15, Walter Bright wrote:
> This issue comes up over and over, in various guises. I feel like
> Yosemite Sam here:
>
> https://www.youtube.com/watch?v=hBhlQgvHmQ0
>
> In that vein, Exceptions are for either being able to recover from
> input/environmental errors, or report them to the user of the application.
>
> When I say "They are NOT for debugging programs", I mean they are NOT
> for debugging programs.
>
This is incorrect.
Yes, the primary purpose of Exceptions is not for debugging, but to
report exceptional state to the user (or some other component of the
system).
But they also have a purpose for debugging, particularly the stack
traces of exceptions. Take what you said:
"Failure to respond properly to an input/environmental error is a bug.
But the input/environmental error is not a bug. If it was, then the
program should assert on the error, not throw. "
So, some component/function Foo detects an environmental error, and
throws and Exception, accordingly. Foo is not responsible for handling
these errors, but some other component is.
Component/function Bar is the one that should handle such an error (for
example, it should display a dialog to the user, and continue the
application). But due to a bug, it doesn't do so, and the Exception goes
all the way through main().
The programmer notices this happening, and clearly recognizes it's a bug
(but doesn't know where the bug is, doesn't know that it's Bar that
should be handling it). Now, what is best, to just have the Exception
message (something like "File not found") displayed to the programmer -
or even an end-user that could report a bug -, or to have the stack
trace of the Exception so that the programmer can more easily look at
which function should be handling it?
--
Bruno Medeiros
https://twitter.com/brunodomedeiros
More information about the Digitalmars-d
mailing list