Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31600
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Abuse of AssertionError? |
| Date | 2015-04-21 11:26 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mh5q67$fkl$1@dont-email.me> (permalink) |
| References | <mh5gl0$96t$1@dont-email.me> <mh5okk$jsi$1@news.albasani.net> |
On 4/21/2015 10:59 AM, j4n bur53 wrote:
> Eric Sosman schrieb:
>> My solution has been to write
>>
>> throw new AssertionError("BUG!");
>
> 1) It depends on the context that runs the code.
> For example sometimes I throw:
>
> throw new RuntimeException()
>
> In such situation, and in my particular case
> I know that the context will not catch it,
> resulting probably in an application abort.
>
> 2) On the other hand sometimes I throw:
>
> throw new IllegalArgumentException();
>
> But I don't need to declare this exception
> either in the method signature. But it
> could be that the context catches this.
>
> 3) Or sometimes I use an exception that is
> clearly visible in the method signature,
> and forces the context to act.
>
> I guess you want scenario 1) ?
Thanks for the comments. I use (3) when the problem is actually
expected to occur and the caller may want to do something about it,
and I use (2) when the problem truly stems from bad arguments rather
than bad "environment." But when the problem isn't the caller's
fault and "shouldn't happen" to begin with, I'll go for (1) in some
form. Sometimes IllegalStateException makes sense, but if it doesn't
I think AssertionError("BUG!") is perhaps a bit more descriptive than
a raw RuntimeException. But I'll consider RuntimeException("BUG!")
as an alternative, if AssertionError seems too much like an abuse.
Thanks again.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Abuse of AssertionError? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-21 08:44 -0400
Re: Abuse of AssertionError? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-21 10:21 -0400
Re: Abuse of AssertionError? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-21 11:21 -0400
Re: Abuse of AssertionError? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-21 11:31 -0400
Re: Abuse of AssertionError? j4n bur53 <janburse@fastmail.fm> - 2015-04-21 16:59 +0200
Re: Abuse of AssertionError? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-21 11:26 -0400
Re: Abuse of AssertionError? Thomas Richter <thor@math.tu-berlin.de> - 2015-04-21 17:05 +0200
csiph-web