wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strang assertion problem" Watch "Strang assertion problem" New topic
Author

Strang assertion problem

Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 207
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

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: http://aspose.com/file-tools
 
subject: Strang assertion problem
 
Similar Threads
a question about exception
Question about assertions...
override and overload method
Assertion
is this a proper mock question for the exam?