Jump to page: 1 2
Thread overview
[phobos] enforce() improvement
Jul 01, 2010
David Simcha
Jul 01, 2010
David Simcha
July 01, 2010
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


July 01, 2010
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 <lars at kyllingen.net>
> To: Phobos mailing list <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:phobos at puremagic.com">phobos at puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos



July 01, 2010
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 <lars at kyllingen.net>
> > To: Phobos mailing list <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:phobos at puremagic.com">phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


July 01, 2010
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



July 01, 2010
Should we put a separate alwaysAssert() function into Phobos that does output the line number and file, and then remove this from enforce()?  I see two use cases for enforce:  As a function that asserts even in release mode, and for real error handling.

I tend to use enforce in a lot of places where I would otherwise use assert, but want to leave the check on in release mode.  I find that I very frequently don't want every array access bounds checked or expensive asserts checked, but still want the asserts that have negligible performance cost to be checked even in release mode.  However, using enforce() like this sometimes devalues it for "real" error handling because you can't catch the exception it throws without possibly catching what's logically an assert error.

On Thu, Jul 1, 2010 at 1:15 PM, Steve Schveighoffer <schveiguy at yahoo.com>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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100701/c5bfe2d2/attachment-0001.html>
July 01, 2010
I think alwaysAssert(expr) can be emulated with relative ease as expr || assert(false).

Andrei

David Simcha wrote:
> Should we put a separate alwaysAssert() function into Phobos that does output the line number and file, and then remove this from enforce()?  I see two use cases for enforce:  As a function that asserts even in release mode, and for real error handling.
> 
> I tend to use enforce in a lot of places where I would otherwise use assert, but want to leave the check on in release mode.  I find that I very frequently don't want every array access bounds checked or expensive asserts checked, but still want the asserts that have negligible performance cost to be checked even in release mode. However, using enforce() like this sometimes devalues it for "real" error handling because you can't catch the exception it throws without possibly catching what's logically an assert error.
> 
> On Thu, Jul 1, 2010 at 1:15 PM, Steve Schveighoffer <schveiguy at yahoo.com <mailto:schveiguy at yahoo.com>> 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
>     <mailto:lars at kyllingen.net>>
>      > To: Discuss the phobos library for D <phobos at puremagic.com
>     <mailto: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
>     <mailto:lars at kyllingen.net>">lars at kyllingen.net
>     <mailto:lars at kyllingen.net>>
>      > > To:
>      > Phobos mailing list <
>      > href="mailto:phobos at puremagic.com
>     <mailto:phobos at puremagic.com>">phobos at puremagic.com
>     <mailto: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 <mailto:phobos at puremagic.com>"
>      > href="mailto:phobos at puremagic.com
>     <mailto:phobos at puremagic.com>">phobos at puremagic.com
>     <mailto:phobos at puremagic.com>">
>      > ymailto="mailto:phobos at puremagic.com <mailto:phobos at puremagic.com>"
>      > href="mailto:phobos at puremagic.com
>     <mailto:phobos at puremagic.com>">phobos at puremagic.com
>     <mailto:phobos at puremagic.com>
>      >
>      > http://lists.puremagic.com/mailman/listinfo/phobos
>      >
>      >
>      >
>      >
>      >
>      > _______________________________________________
>      > phobos mailing
>      > list
>      >
>      > href="mailto:phobos at puremagic.com
>     <mailto:phobos at puremagic.com>">phobos at puremagic.com
>     <mailto: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
>     <mailto:phobos at puremagic.com>">phobos at puremagic.com
>     <mailto: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 <mailto:phobos at puremagic.com>
>     http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
July 01, 2010
I think it would be a good improvement to add such structure to exceptions. So toString() would continue to print essentially the same message, but it would assemble it from the separately-available properties file, line, and reason.

Go for it, or submit a ticket so it's not forgotten.

Andrei

Lars Tandle Kyllingstad wrote:
> 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 <lars at kyllingen.net>
>>> To: Phobos mailing list <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:phobos at puremagic.com">phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>>
>> 
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
July 01, 2010
On Thu, Jul 1, 2010 at 1:45 PM, Andrei Alexandrescu <andrei at erdani.com>wrote:

> I think alwaysAssert(expr) can be emulated with relative ease as expr ||
> assert(false).
>
>
>>
But that doesn't give you a line number and file name in release mode either.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100701/1ba9ed1c/attachment.html>
July 01, 2010
There is no need to add anything, Throwable already has this structure. That was the main point behind my proposal:  enforce() puts the information in the wrong place.

I'll look into it.

-Lars



On Thu, 2010-07-01 at 10:47 -0700, Andrei Alexandrescu wrote:
> I think it would be a good improvement to add such structure to exceptions. So toString() would continue to print essentially the same message, but it would assemble it from the separately-available properties file, line, and reason.
> 
> Go for it, or submit a ticket so it's not forgotten.
> 
> Andrei
> 
> Lars Tandle Kyllingstad wrote:
> > 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 <lars at kyllingen.net>
> >>> To: Phobos mailing list <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:phobos at puremagic.com">phobos at puremagic.com
> >> http://lists.puremagic.com/mailman/listinfo/phobos
> >>
> >>
> >> 
> >> _______________________________________________
> >> phobos mailing list
> >> phobos at puremagic.com
> >> http://lists.puremagic.com/mailman/listinfo/phobos
> > 
> > 
> > _______________________________________________
> > phobos mailing list
> > phobos at puremagic.com
> > http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


July 01, 2010
I re-read this thread.  I understand now that you don't want to remove that information, just not print it via msg?  Sorry for the opposition.  I agree that the message shouldn't contain redundant info.

As long as the default handler prints the information out, I'm ok with that.  Having as much information as possible when something goes unexpectedly wrong is the best case scenario for a developer.

-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 2:06:45 PM
> Subject: Re: [phobos] enforce() improvement
> 
> There is no need to add anything, Throwable already has this structure.
That
> was the main point behind my proposal:  enforce() puts the
information
> in the wrong place.

I'll look into it.

-Lars



On
> Thu, 2010-07-01 at 10:47 -0700, Andrei Alexandrescu wrote:
> I think it
> would be a good improvement to add such structure to
> exceptions. So
> toString() would continue to print essentially the same
> message, but it
> would assemble it from the separately-available
> properties file, line,
> and reason.
> 
> Go for it, or submit a ticket so it's not forgotten.
> 
> Andrei
> 
> Lars Tandle Kyllingstad wrote:
> > 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 <
> ymailto="mailto:lars at kyllingen.net" 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
> 
> 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



« First   ‹ Prev
1 2