As specified in oracle official tutorial , it states that:
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.
If I have an Application interacting with database using JDBC
, And I have a method that takes the argument as the int item
and double price
. The price
for corresponding item is read from database table. I simply multiply the total number of item
purchased with the price
value and return the result. Although I am always sure at my end(Application end) that price field value in the table could never be negative .But what if the price value comes out negative? It shows that there is a serious issue with the database side. Perhaps wrong price entry by the operator. This is the kind of issue that the other part of application calling that method can't anticipate and can't recover from it. It is a BUG
in your database. So , and IllegalArguementException()
should be thrown in this case which would state that the price can't be negative
.
I hope that I have expressed my point clearly..