wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AssertionError clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "AssertionError clarification" Watch "AssertionError clarification" New topic

AssertionError clarification

Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

Hello all,

I suppose programmatically thrown exceptions mean those exceptions which are thrown
usign throw keyword ...
In K&B it is written that AssertionError is programmatically thrown ,
Is it exception to JVM thrown exceptions??
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

There is difference between Error and Exception.

Yes Assertions are thrown programmatically but the their purpose is different.

There will be difference given in K&B book only.

Its very common and if I start explaining the concept here then it will make a huge post.

You can also refer wikipedia for Java Assertions.

Java Experience
Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

Hello sunny...
I just wanted to know how AssertionError is considered
to be programmatically thrown or that definition is too general,
apart from that i think i understood asertions....
Dan Daemler

Joined: Jan 20, 2011
Posts: 4
I found that statement a little hazy myself. After re-reading pg. 379-380:

JVM exceptions
Those exceptions or errors that are either exclusively or most logically thrown by the JVM.

Programmatic exceptions
Those exceptions that are thrown explicitly by application and/or API programmers

JVM: If you try to call a method on a null reference variable, the JVM will throw a NullPointerException.

Programmatic: By putting an assert statement in your code you are actively deciding to throw an AssertionError if your assumption isn't true.

I guess that's why they consider it programmatically thrown. An AssertionError will never be thrown unless you go out of your way to use assertions in your code and/or turn on assertions when you run the program. Just like some of the other exceptions won't be thrown unless you (or one of the API programmers) decide to throw them. On the other hand, a NullPointerException can be thrown by the JVM whether you mean to or not.

Since I still don't know 100% which exceptions are programmatic vs. JVM, I will just memorize the chart on page 382.
Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

hello Dan Daemler ,
I too assumed it in the same way...
Also note that all JVM thrown exceptions are unchecked and
programmatically thrown exceptions are may be checked or unchecked...

A good tutorial about exceptions...
I agree. Here's the link: http://aspose.com/file-tools
subject: AssertionError clarification
It's not a secret anymore!