File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes throw assertion error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "throw assertion error" Watch "throw assertion error" New topic
Author

throw assertion error

Heba Mahmoud
Ranch Hand

Joined: Apr 26, 2009
Posts: 62


what will be the output ?
a throwable is throwen by main
or an exception is throwen by main


SCJP Pass 85%....
Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

What has the output when you ran it?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Heba Mahmoud
Ranch Hand

Joined: Apr 26, 2009
Posts: 62
the output is
Exception in thread "main" java.lang.AssertionError

i know that error can't be handle by exception handler. but what i understand from output that the assertionerror is an exception
that means that it is may be a child for excepton class so why catch clause fails to handle.

and also ....at the same time i wondered why it cause an excption not an error
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

java.lang.AssertionError is a Child of java.lang.Error and not of java.lang.Exception and because of that it is not caught in your catch-block.
Heba Mahmoud
Ranch Hand

Joined: Apr 26, 2009
Posts: 62
so the right answer will be a throwable is thrown by main

thanks
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Saying specifically it will be an Error not throwable. But because throwable is parent of both Error and Exception so in case of both you can say that if is a throwable but actually it will be Error or Exception.
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
Error and RuntimeException are unchecked exceptions so the compiler doesn't care whether you catch them, declare them or ignore them. Changing line 15 on your code to say (Error e) will bear out what Wouter has said.


Rajeev Trikha (SCJP 6)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: throw assertion error