Vinod Vijay Nair
http://www.lifesbizzare.blogspot.com || OCJP:81%
Vinod Vijay wrote:Please clear my following doubts:-
1)As book says, we can do exception handling(using try-catch blocks) for unchecked exceptions but the compiler will not check. Does that mean a program pre-mature death or execution termination if such things happen like unchecked(runtime exceptions -> nullpointerexception, etc) ?
2) Now I think there is a contradiction on page 348, there is an exercise to do (True/False) for us. Point# 4 asks "Only 'compiler checked' exceptions can be caught". I said Yes as till now I was thinking like this only. But my answers was wrong. On page 351, solutions are given and now book says False, runtime exceptions can be caught.
What does it mean? Please tell me which one is correct.
Vinod Vijay Nair
Vinod Vijay wrote:
Vinod Vijay wrote:Please clear my following doubts:-
1)As book says, we can do exception handling(using try-catch blocks) for unchecked exceptions but the compiler will not check. Does that mean a program pre-mature death or execution termination if such things happen like unchecked(runtime exceptions -> nullpointerexception, etc) ?
2) Now I think there is a contradiction on page 348, there is an exercise to do (True/False) for us. Point# 4 asks "Only 'compiler checked' exceptions can be caught". I said Yes as till now I was thinking like this only. But my answers was wrong. On page 351, solutions are given and now book says False, runtime exceptions can be caught.
What does it mean? Please tell me which one is correct.
Please explain my two queries in detail with some example. Also about True/False exercise.
http://www.lifesbizzare.blogspot.com || OCJP:81%
Vishal Hegde wrote:Unchecked Exception you can think about some exception that occurs during the compilation of the program...
John Jai wrote:
Vishal Hegde wrote:Unchecked Exception you can think about some exception that occurs during the compilation of the program...
Please note that Exceptions occur during the execution of the program
http://www.lifesbizzare.blogspot.com || OCJP:81%
Vishal Hegde wrote:
I will answer your 2nd question : you can catch checked as well as unchecked exception , but its mandatory that you catch a checked exception.
The first question is confusing to me what actually do you mean by pre-mature death???
Vinod Vijay Nair
Regards
Maganti Surya
Surya Narayana Murthy wrote:Hello,
Runtime Exceptions are called as Unchecked Exceptions. Error and its subclasses also throw Unchecked Exceptions.
NullPointerException is an unchecked Runtime Exception. OutOfMemory is Error Unchecked Exception.
Example of NullPointer Exception:
String s;
System.out.prinlnt(s.toUpperCase()) will throw null pointer Exception as s is not assigned to any object and it contains null and we are trying to print s.toUpperCase() and it compiles but fails at runtime.
If still any queries regarding exceptions let me know.
Vinod Vijay Nair
forces us to use try-catch block
And If we do exception handling for unchecked exception then it is good and [b]will be caught else will not (and execution terminates).
Vishal Hegde wrote:Checked Exception you can think of it as a kind of Customized Exception we are creating
Unchecked Exception you can think about some exception that occurs during the compilation of the program and is caught only by runtime Inspectors ;)
Vishal Hegde wrote:but its mandatory that you catch a checked exception.
It’s called abrupt completion. You should read that whole Java™ Language Specification chapter (it’s not easy to read), as well as the section in the Java Tutorials.Vinod Vijay wrote: . . . Does that mean a program pre-mature death or execution termination . . .
Regards
Maganti Surya
Jeff Verdegan wrote:
Vishal Hegde wrote:Checked Exception you can think of it as a kind of Customized Exception we are creating
We can create our own custom checked and unchecked exceptions, and the exceptions in the core API are both checked and unchecked, so that's not a particularly useful way to view them.
Unchecked Exception you can think about some exception that occurs during the compilation of the program and is caught only by runtime Inspectors ;)
No, that would be wrong. Exceptions don't occur during compile time.
The right way to think about them is the way they're explained in the docs and tutorials: Checked exceptions are for things that are expected to go wrong and that we have a good chance of recovering from, and unchecked exceptions are those that indicate either a bug in the code or a serious problem in the JVM, and we generally cannot recover from them, and generally should not try to.
http://www.lifesbizzare.blogspot.com || OCJP:81%
http://www.lifesbizzare.blogspot.com || OCJP:81%
Vishal Hegde wrote:
How Unchecked Exception can be customised??
Consider Paul's rocket mass heater. |