• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Strang assertion problem  RSS feed

 
Ranch Hand
Posts: 220
  • 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
 
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 ]
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!