Program logic bugs vs input/environmental errors

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 16:59:43 PDT 2014


Walter Bright:

> Even if that is what you wanted, you won't get that from 
> FileException, as it will only show file/lines emanating from 
> calls inside std.file, not from higher level callers.

Can't we use the template arguments like __LINE__ to offer the 
line of code in the IO function in user code?


> Besides, take a bit of care when formulating a string for 
> exceptions, and you won't have any trouble grepping for it. 
> This isn't rocket science.

The exception is generated inside library code, not in user code. 
There's nothing to grep in the user code. The D script often 
looks like this:

void main() {
     import std.stdio;
     auto file_name = "some_file;
     // some code here
     auto file_name1 = file_name ~ "1.txt";
     auto f1 = File(file_name1);
     // some code here
     auto file_name2 = file_name ~ "2.txt";
     auto f2 = File(file_name2, "w");
     // some code here
}


> Presenting internal debugging data to users for 
> input/environmental errors is just bad programming practice.7 
> We shouldn't be enshrining it in Phobos and presenting it as a 
> professional way to code.

The file/line of code is not meant to replace serious practices 
for dealing with I/O failures in serious D programs.

Bye,
bearophile


More information about the Digitalmars-d mailing list