- 3,715,709 Users
- 2,242,839 Discussions
- 7,845,504 Comments
Forum Stats
Discussions
Categories
- 17 Data
- 362.2K Big Data Appliance
- 7 Data Science
- 1.6K Databases
- 467 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 22 Multilingual Engine
- 487 MySQL Community Space
- 3 NoSQL Database
- 7.6K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 416 SQLcl
- 42 SQL Developer Data Modeler
- 184.9K SQL & PL/SQL
- 21K SQL Developer
- 1.9K Development
- 3 Developer Projects
- 32 Programming Languages
- 135.1K Development Tools
- 8 DevOps
- 3K QA/Testing
- 248 Java
- 5 Java Learning Subscription
- 10 Database Connectivity
- 66 Java Community Process
- 1 Java 25
- 9 Java APIs
- 141.1K Java Development Tools
- 6 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 135 Java 8 Questions
- 86.2K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 10 Java SE
- 13.8K Java Security
- 3 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 125 LiveLabs
- 30 Workshops
- 9 Software
- 3 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 3 Deutsche Oracle Community
- 10 Español
- 1.9K Japanese
- 2 Portuguese
Checked Exceptions vs RuntimeException

Hello,
I just read the oracle documentation about Exceptions.
The Catch or Specify Requirement (The Java™ Tutorials > Essential Classes > Exceptions)
The definition for Error is clear, but the definition for the checked Exceptions and RuntimeException are confusing because therorically we can always recover from an Exception.
In doc from Unchecked Exceptions — The Controversy (The Java™ Tutorials > Essential Classes > Exceptions):
"Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception."
For example, NumberFormatException is RuntimeException but we often recover from this situation by asking the client to enter a valid number, isn't ?
So, how could we differentiate ?
Thank you
Answers
-
In the above mentioned quote from docs, client means the client programmer, who is using the oracle code in this case. and could be using an API developed by you or a third party. It does not mean the user of the program as you are assuming.
If you are making an API that can/would be used by client programmers, who may not have direct contact with you (common in opensource/ github projects), the client programmer would look only at the java docs to see what type of exceptions are being generated.
With checked exceptions the client have to handle exception
With Unchecked exception the client has an option to handle or leave handling of exception. NumberFormatException would be thrown by Java Runtime. It would propagate to the runtime level. The client programmer may choose to handle this unexpected situation or he may leave it to the Runtime environment.
Note that exceptions are not a means to control program flow. but a means to handle unexpected situations (alarm client programmer in this case) .