aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Hi,
Regarding exceptions, I realize you are only required to handle checked exceptions, and are not required to handle Runtime or Error exceptions. Is there anything wrong with handling the Runtime or Error exceptions though, it is illegal to do so?
Thanks,
TM
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Also,
Can you throw Error or Runtime exceptions?
Thanks,
TM
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
Errors can occur at many points of the program, and recovery from them is almost impossible. Its subclass RuntimeException, are not checked by the compiler. It is legal to catch RuntimeExceptins.
you can read more about it at chapter 11 of JLS
Hanna


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
hi,
"subtypes of error or runtimeException are unchecked, so the compiler doesn't enforce the handle or declare rule. You're free to handle them, and you're free to declare them, but compiler doesn't care one way or the other."
from K&B
-PC
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Thank you.
TM
Davide Zanichelli
Greenhorn

Joined: Aug 22, 2003
Posts: 29
I know that usually it's quite unreasonable catch and try to recover from an error (OutOfMemoryError...), but i think it make sense to try to recover from an AssertionError, since if i'm using assertions to check the pre-conditions of a private method, i've more or less the same chances to recover as catching an InvalidArgumentException thrown from a public method...
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Davide
Assertion Errors are not be handled. What if you turn off the assertion and your error recovery mechanism would fail then. I can't think of any practical situation where you should handle assertion error.
Davide Zanichelli
Greenhorn

Joined: Aug 22, 2003
Posts: 29
i just think that a general handler could catch this assertion errors, just to avoid crashing all the application when only some part of it could be closed and restarted. same as a global catch of exception would do for uncaught errors. and if you don't have assertions enabled, the handler would have simply no job
what do you think?
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Davide
In case we need to check the pre-conditions of a private method and you want to recover then I would suggest you use another error. I guess that would be more appropriate.
[ August 29, 2003: Message edited by: Anupam Sinha ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions
 
Similar Threads
Exceptions
compile time exception
how to handle the runtime exceptions in jsp
Exception handling
Exception handling