[phobos] enforce() improvement

Lars Tandle Kyllingstad lars at kyllingen.net
Thu Jul 1 11:20:16 PDT 2010


I admit the example could be better, but I think you're deliberately
missing the point. :)

        User:
                Hey, Application, open this file for me.
        Application:
                Sorry, no can do.  In the source file app.d, on line
                123, there was an attempt to open a file which you don't
                have permission to open.
        User:
                Man, that's way more than I needed to know.  What's up
                with that?
        Developer:
                Yeah.. The I/O library just throws a plain Exception
                regardless of which error actually occurs, and the only
                way to figure out what went wrong is to read the
                message.  What am I supposed to do?  Whip out a regex
                engine just to remove the file and line number?

-Lars

On Thu, 2010-07-01 at 10:15 -0700, Steve Schveighoffer wrote:
> User: your application exited with an error message
> Developer: What was the message?
> User: Need nonnegative i
> Developer:  Well, don't pass in a negative i then!
> 
> :)
> 
> -Steve
> 
> 
> 
> ----- Original Message ----
> > From: Lars Tandle Kyllingstad <lars at kyllingen.net>
> > To: Discuss the phobos library for D <phobos at puremagic.com>
> > Sent: Thu, July 1, 2010 10:15:36 AM
> > Subject: Re: [phobos] enforce() improvement
> > 
> > The library user would still get the information, 
> > because
> Throwable.toString() would still give the file and line number, and 
> > like
> I said, Throwable.file and Throwable.line are supposed to be filled 
> > with
> that information.  My point was that enforce() puts the information 
> > in
> Throwable.msg, which I find completely redundant.
> 
> Also, if you are 
> > using plain enforce() for error checking (like Phobos
> does in a lot of 
> > places), Throwable.msg is your only source of
> information to pass to the 
> > user, since enforce() by default throws an
> Exception and not an 
> > InsightfulInformationException.
> 
> -Lars
> 
> 
> 
> On Thu, 2010-07-01 
> > at 07:00 -0700, Steve Schveighoffer wrote:
> > I disagree.  The "user" 
> > in this case, is the user of the library code.  He does in fact need to 
> > know the file/line that caused the problem, and more useful would be the full 
> > stack trace so he can see where his code used the offending value.
> > 
> > 
> > If you are relying on enforce to give insightful error messages to an 
> > actual user (that is, someone who runs your program), then you need some 
> > training in user interface design :)
> > 
> > -Steve
> > 
> > 
> > 
> > 
> > ----- Original Message ----
> > > From: Lars Tandle 
> > Kyllingstad <
> > href="mailto:lars at kyllingen.net">lars at kyllingen.net>
> > > To: 
> > Phobos mailing list <
> > href="mailto:phobos at puremagic.com">phobos at puremagic.com>
> > > 
> > Sent: Thu, July 1, 2010 9:50:15 AM
> > > Subject: [phobos] enforce() 
> > improvement
> > > 
> > > Often, at least in small programs, when 
> > an exception is thrown you just
> > want 
> > > to present a sensible 
> > message to the user and abort the 
> > > current
> > operation.  
> > Example:
> > 
> >         void 
> > > 
> > doStuff(int i) { enforce(i >= 0, "Need nonnegative i"); }
> > 
> > 
> >  
> > >       try 
> > doStuff(-1);
> >         catch 
> > > (Exception 
> > e) writeln("Error: ", e.msg);
> > 
> > In this case, the user will 
> > 
> > > see
> > 
> >         Error: b.d(5): 
> > Need nonnegative 
> > > i
> > 
> > My point is that the user 
> > doesn't need to see the file and line 
> > > number
> > that caused 
> > the error.  This is only useful for the 
> > > programmer.  So 
> > I
> > suggest we make either of the following changes to 
> > > 
> > enforce():
> > 
> >      1. Drop the file and line number 
> > from the 
> > > message.  The Throwable
> >      
> >    class has dedicated 
> > > 'file' and 'line' fields which we 
> > can
> >         populate 
> > > with that 
> > information without polluting the error
> >        
> > 
> > > message.
> >      2. Another option is to 
> > include the file and line 
> > > only in debug
> >    
> >      builds.
> > 
> > -Lars 
> > > 
> > 
> > 
> > 
> > _______________________________________________
> > phobos mailing 
> > 
> > > list
> > 
> > > href="mailto:
> > ymailto="mailto:phobos at puremagic.com" 
> > href="mailto:phobos at puremagic.com">phobos at puremagic.com">
> > ymailto="mailto:phobos at puremagic.com" 
> > href="mailto:phobos at puremagic.com">phobos at puremagic.com
> > 
> > http://lists.puremagic.com/mailman/listinfo/phobos
> > 
> > 
> > 
> >      
> > 
> > _______________________________________________
> > phobos mailing 
> > list
> > 
> > href="mailto:phobos at puremagic.com">phobos at puremagic.com
> > 
> > href="http://lists.puremagic.com/mailman/listinfo/phobos" target=_blank 
> > >http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> _______________________________________________
> phobos 
> > mailing list
> 
> > href="mailto:phobos at puremagic.com">phobos at puremagic.com
> 
> > href="http://lists.puremagic.com/mailman/listinfo/phobos" target=_blank 
> > >http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
>       
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos




More information about the phobos mailing list