harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Loenko" <mloe...@gmail.com>
Subject Re: More helpful error messages
Date Sun, 26 Mar 2006 10:24:41 GMT
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