SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Paul Clapham wrote:Because the people who designed the language decided it would be a good idea.
Shiva.Om Kumar wrote:To prevent NFE, if I am having catch for it then I would do same for SQL handling too, why Java has mandatory to catch it?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Paul Clapham wrote:
Paul Clapham wrote:Because the people who designed the language decided it would be a good idea.
Seriously, that's the answer to pretty much every question of the form "Why does feature X exist (or fail to exist) in Java?" The designers didn't publish a detailed architectural document explaining why they made the decisions they made. However, if you want to discuss why it might be a good idea, or a bad idea, or you want to ask a question about how it works, then do go ahead and ask such a question.
Winston Gutkowski wrote:
Shiva.Om Kumar wrote:To prevent NFE, if I am having catch for it then I would do same for SQL handling too, why Java has mandatory to catch it?
It doesn't. It just requires that if you don't catch it, the method declares that it might be thrown.
However, it tends to suggest that it might not be a bad idea to use a try...catch block. Do you have any particular objection to them?
Winston
Ninad Kulkarni wrote:If code is behaving unexpectedly we can identify root cause of problem by using exception.
Handling of Checked as well as Unchecked exceptions are totally depends on design.
Shiva.Om Kumar wrote:I don't have any objection...
I intend to understand why for one kind of Exception (SQLE) one need to (mandatory) catch or use throws
but for other (NFE) one can code without using catch / throws
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:A runtime Exception is one which occurs entirely inside the runtime system, and other Exceptions are caused by occurrences outside the runtime.
so I believed it, but I have know the tutorials to be mistaken elsewhere.internal to the application
The Java Tutorials wrote:
The Three Kinds of Exceptions
The first kind of exception is the checked exception. These are exceptional conditions that a well-written application should anticipate and recover from. For example, suppose an application prompts a user for an input file name, then opens the file by passing the name to the constructor for java.io.FileReader. Normally, the user provides the name of an existing, readable file, so the construction of the FileReader object succeeds, and the execution of the application proceeds normally. But sometimes the user supplies the name of a nonexistent file, and the constructor throws java.io.FileNotFoundException. A well-written program will catch this exception and notify the user of the mistake, possibly prompting for a corrected file name.
Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses.
The second kind of exception is the error. These are exceptional conditions that are external to the application, and that the application usually cannot anticipate or recover from. For example, suppose that an application successfully opens a file for input, but is unable to read the file because of a hardware or system malfunction. The unsuccessful read will throw java.io.IOError. An application might choose to catch this exception, in order to notify the user of the problem — but it also might make sense for the program to print a stack trace and exit.
Errors are not subject to the Catch or Specify Requirement. Errors are those exceptions indicated by Error and its subclasses.
The third kind of exception is the runtime exception. These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from. These usually indicate programming bugs, such as logic errors or improper use of an API. For example, consider the application described previously that passes a file name to the constructor for FileReader. If a logic error causes a null to be passed to the constructor, the constructor will throw NullPointerException. The application can catch this exception, but it probably makes more sense to eliminate the bug that caused the exception to occur.
Runtime exceptions are not subject to the Catch or Specify Requirement. Runtime exceptions are those indicated by RuntimeException and its subclasses.
Errors and runtime exceptions are collectively known as unchecked exceptions.
Isn’t it quicker to enumerate the places where guidelines aren’t violated?Mike Simmons wrote:. . . There are various places where this guideline is violated, . . .
Mike Simmons wrote: I would further add that the name RuntimeException is an extremely crappy and useless name, in my opinion, as it has no real correlation with what it means. I would agree with most of the other recent posts, however. Perhaps I am missing something about what you mean here - can you give some examples?
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Mike Simmons wrote: There are various places where this guideline is violated, especially nowadays when whole frameworks like Spring and Hibernate make most everything into a runtime exception. But I agree it's how Sun apparently wanted them to be used, most of the time.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Don’t do that. Maybe they will suffer worse if they are just alive!Raghavan Muthu wrote:. . . brutally killing those people for this blatant sin! . . .
Campbell Ritchie wrote:
Don’t do that. Maybe they will suffer worse if they are just alive!Raghavan Muthu wrote:. . . brutally killing those people for this blatant sin! . . .
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu wrote:
Mike Simmons wrote: I would further add that the name RuntimeException is an extremely crappy and useless name, in my opinion, as it has no real correlation with what it means. I would agree with most of the other recent posts, however. Perhaps I am missing something about what you mean here - can you give some examples?
To me it makes a clear sense when I look at the definition of the terms , "Compile time exception" Vs "Runtime Exception".
Raghavan Muthu wrote:Not just Spring, Hibernate like frameworks , I have seen few other custom application frameworks abusing Runtime exception as nowhere you can see a single checked exception!
Raghavan Muthu wrote:Whenever I wear a developer hat, I feel like brutally killing those people for this blatant sin!
Mike Simmons wrote:
Raghavan Muthu wrote:Not just Spring, Hibernate like frameworks , I have seen few other custom application frameworks abusing Runtime exception as nowhere you can see a single checked exception!
Yay!
Raghavan Muthu wrote:Whenever I wear a developer hat, I feel like brutally killing those people for this blatant sin!
And I feel like celebrating them for getting rid of a bad, poorly-implemented idea.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Campbell Ritchie wrote:Anyway, nice to see you back, RM.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|