File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Strang assertion problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strang assertion problem" Watch "Strang assertion problem" New topic

Strang assertion problem

Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 214
Dear sir,
I read a materail talking about the assertions, its example is strange.
here is the content :
public aClass {
public void aMethod(int argument) {
Foo foo = null;
//...somehow get a Foo object
if(!(foo != null ) {
throw new AssertionError ( "can
t get a Foo, argument="+argument);
the problem is why the method doesn't have throws clause to indicate it throw AssertionError,
just like public void aMethod(int argument) throws AssertionError {......}
Please help
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Benson, it's because assertionError is a subclass of Error. Remember that unchecked exceptions are exceptions that are subclass of RuntimeException and Error. You can declare it if you want, but the compiler only complains when dealing with checked exceptions.

[ August 13, 2003: Message edited by: Andres Gonzalez ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
I agree. Here's the link:
subject: Strang assertion problem
It's not a secret anymore!