harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Magnusson, Geir" <geir.magnus...@intel.com>
Subject Re: More helpful error messages
Date Sun, 26 Mar 2006 18:10:13 GMT
The point was to illustrate having useful information in the message.  Optime any way you see
fit.

That said, given that you are throwing an exception... do we really care?  I'm praying that
we don't have apis that throw exceptions as a   normal result of operation.....

Geir

 -----Original Message-----
From: 	Mikhail Loenko [mailto:mloenko@gmail.com]
Sent:	Sun Mar 26 02:25:18 2006
To:	harmony-dev@incubator.apache.org; geir@pobox.com
Subject:	Re: More helpful error messages

As we discussed earlier we fight for performance not only in case of
'positive' behavior but also when methods throw exceptions.

Throwing exceptions with predefeined constant message is much
faster then with string concatenation.

Thanks,
Mikhail

2006/3/25, Geir Magnusson Jr <geir@pobox.com>:
>
>
> Mark Hindess wrote:
> > While reading some of the classlib code I've spotted a few examples of
> > code like:
> >
> >   if (A || B) throw Exception("A or B");
> >
> > Please can we agree, for the sake of the sanity of those trying to
> > debug code throwing exceptions like this, to split these into two
> > statements:
> >
> > if (A) throw Exception("A");
> > if (B) throw Exception("B");
>
> This isn't even debatable.
>
> >
> > For instance, modules/security/src/common/javasrc/java/security/KeyStore.java,
> > line 492 has:
> >
> >         if ((alias == null) || (entryClass == null)) {
> >             throw new NullPointerException("alias or entryClass is null");
> >         }
> >
> > which could be split in to two distinct cases with unambiguous messages.
> >
> > Personally, I'd even split this test, from
> > modules/security/src/common/javasrc/java/security/MessageDigestSpi.java:
> >
> >         if ((offset < 0) || (offset + len > buf.length)) {
> >             engineReset();
> >             throw new DigestException("Incorrect offset or len value");
> >         }
> >
> > since if the first condition is true then we know for certain that the
> > offset is invalid even if we'd still have to report the more ambiguous
> > error for the second test.
>
> or
>
>   if ( A || B ) {
>      engineReset();
>      throw new DigestException( A ?
>                 "offset incorrect  = " + offset
>                 : "incorrect len value ");
> }
>
> >
> > Regards,
> >  Mark.
> >
> > --
> > Mark Hindess <mark.hindess@googlemail.com>
> > IBM Java Technology Centre, UK.
> >
> >
>

Mime
View raw message