Program logic bugs vs input/environmental errors

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 1 08:21:22 PDT 2014


On 10/1/14 11:00 AM, Andrej Mitrovic via Digitalmars-d wrote:
> On 10/1/14, Steven Schveighoffer via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> No, this is lazy/incorrect coding. You don't want your user to see an
>> indecipherable stack trace on purpose.
>
> So when they file a bug report are you going to also ask them to run
> the debugger so they capture the stack trace and file that to you?
> Come on.
>

No what I mean is:

./niftyapp badfilename.txt

Result should be:

Error: Could not open badfilename.txt, please check and make sure the 
file exists and is readable.

Not:

std.exception.ErrnoException at std/stdio.d(345): Cannot open file 
`badfilename.txt' in mode `rb' (No such file or directory)
----------------
5   testexception                       0x0000000104fad02d ref 
std.stdio.File std.stdio.File.__ctor(immutable(char)[], const(char[])) + 97
6   testexception                       0x0000000104f8d735 _Dmain + 69
7   testexception                       0x0000000104f9f771 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll().void __lambda1() + 33
8   testexception                       0x0000000104f9f6bd void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
9   testexception                       0x0000000104f9f71d void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() + 45
10  testexception                       0x0000000104f9f6bd void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
11  testexception                       0x0000000104f9f639 _d_run_main + 449
12  testexception                       0x0000000104f8d75c main + 20
13  libdyld.dylib                       0x00007fff8fb2a5fd start + 1
14  ???                                 0x0000000000000001 0x0 + 1

If it's an error due to *user input*, you should not rely on the 
exception handling of the runtime, you should have a more user-friendly 
message.

Obviously, if you fail to handle it, the full trace happens, and then 
you must fix that in your code.

It's for your benefit too :) This way you get less nuisance 
troubleshooting calls since the error message is clearer.

-Steve


More information about the Digitalmars-d mailing list