Why runtime exceptions are not checked
Learn more. Asked 10 years, 9 months ago. Active 3 years, 8 months ago. Viewed 5k times. Improve this question. Add a comment. Active Oldest Votes. They came up with these three types: Checked exceptions are used for errors, which may occur at run-time and are expected sort of , for example, IOException.
Improve this answer. Dirk Dirk This has nothing to with the JVM. In a way, all exceptions can be thought of as being generated by the JVM — Dirk. The view is that, even in a language that supports checked exceptions, there are cases where the use of checked exceptions is not appropriate Clearly mentions that it represents scenarios that do not allow for recovery. Favonius Favonius Joonas Pulakka Joonas Pulakka Look at the name of the exception "RunTime". Daniel Daniel When you can handle the recovery of the state of Object , go for Checked Exception.
When you cannot handle the recovery go for UnCheckedException. Mostly API developers go for Runtime Exception , they do not want to enforce handling exception by the user, since they themselves do not know how to handle it. Dead Programmer Dead Programmer 12k 20 20 gold badges 77 77 silver badges bronze badges.
Neeraj Joshi Neeraj Joshi 26 1 1 silver badge 4 4 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
Because the Java programming language does not require methods to catch or to specify unchecked exceptions RuntimeException , Error , and their subclasses , programmers may be tempted to write code that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch any exceptions.
Although this may seem convenient to the programmer, it sidesteps the intent of the catch or specify requirement and can cause problems for others using your classes. Why did the designers decide to force a method to specify all uncaught checked exceptions that can be thrown within its scope?
Any Exception that can be thrown by a method is part of the method's public programming interface. Those who call a method must know about the exceptions that a method can throw so that they can decide what to do about them.
Save Article. Improve Article. Like Article. Previous Types of Exception in Java with Examples. Next Try, catch, throw and throws in Java. Recommended Articles. Article Contributed By :.
Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Java. More related articles in Java. We use cookies to ensure you have the best browsing experience on our website.
0コメント