| Author |
Can we catch errors in java code
|
Ram Chhabra
Ranch Hand
Joined: Jan 07, 2008
Posts: 48
|
|
Hi,
Can we catch error in java code like, can we catch OutOfMemoryError, ThreadDeath etc.
Thanks,
Ram
|
 |
kurt hanni
Ranch Hand
Joined: Aug 11, 2007
Posts: 140
|
|
Yes you can, Error is a sublass of Throwable.
|
SCJA, SCJP, SCJD, SCMAD, SCWCD, SCBCD, SCDJWS, SCEA, SOA, Spring Certified, OCP MySQL 5 Developer, PMP
|
 |
Ram Chhabra
Ranch Hand
Joined: Jan 07, 2008
Posts: 48
|
|
Thanks,
Can you please give any one error which we cannot handle
|
 |
kurt hanni
Ranch Hand
Joined: Aug 11, 2007
Posts: 140
|
|
All error objects can be handled. they are all subclass of Error which is a subclass of Throwable.
Remember you must avoid handling errors.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
And there is nothing much you can do even you catch an Error.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Ram Chhabra
Ranch Hand
Joined: Jan 07, 2008
Posts: 48
|
|
|
Thanks a lot for clarifications
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Vijitha Kumara wrote:And there is nothing much you can do even you catch an Error.
Depends on the error. A NoClassDefError means a class available at compile time is no longer available. A UnsatisfiedLinkError means a native library cannot be used (it can't be found, or it's missing a dependency). You can catch both and decide to use a workaround.
But I agree that catching errors should be done with very much caution. And OutOfMemoryErrors should never be caught at all.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Can we catch errors in java code
|
|
|