• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strang assertion problem

 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Benson
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic