Not just look at a few more citations from Effective Java. 2
These are pretty simple steps and do not be doing any demonstrably scuzz them frontrunner's I don't 3
57 NHS use exceptions only for exceptional conditions right. 4
Grenada don't use them for controlling the flow of your program. 5
An here's an example where an exception is used to control the flow of the program. 6
Helots that you'll be a parceling a history document get hitched him and document it up as it did by 7
some kind of it treaty. 8
Dr. So we will be reading through the different notes of the Hatchie imagery hit the next night a third 9
would read and the next element in the history of my document no after which I was the last and it meant 10
then me and the next item added. 11
It would throw an exception. 12
So here you're are catching that exception. 13
And we are done things that you're doing some complex logic. 14
So the programs can go is dictated by the generation of exception. 15
And this is something you should never do. 16
You could instead do something like this. 17
Well you would have a separate method that does great or not there are any more elements to recovers 18
only if there is an element to hours then you would invoke the next item at that get this you don't 19
have the exception so you need to write your logic in this way but not rely on exceptions for our growth 20
. 21
Nectars I don't for twenty nine inches avoid unnecessary use of checked exceptions know the technical 22
options are great at making our programs reliable in the event of any exceptional conditions. 23
But if you scurrilously then that would make the API far less pleasant to use as a force the API client 24
to handle those exceptions. 25
So this is an extra burden on the clients so use it or leave there can be an unpreventable exceptional 26
condition under a client can actually recover from it. 27
If one or both of these conditions do not hold then an exception would be more appropriate. 28
So just be careful when you're thinking of using checked exceptions next is item 60 which is filled 29
with the use of standard exceptions. 30
And that's because the exceptions that come July we should be good enough most of the time. 31
And so you don't have to introduce any new exception of process and here are some benefits of reusing 32
existing exceptions the first one is a very important one using standard exceptions would make it easier 33
to understand you would be a Consequently it would also make the program so if you are able at a glance 34
easy to follow on here are a few commonly used exceptions and we're going to discuss them as there were 35
already briefly discussed earlier. 36
Next is item 60 do under this document all exceptions thrown by each method. 37
According to this item it is very important to describe all the exceptions that a method can throw a 38
using the method properly. 39
Generally this addition is also often why later sometimes even public ice so when you're throwing exceptions 40
exercise some patience big time to document all the exceptions that you and motard gross just recall 41
that Tostig is used for documenting exceptions not ask for tidbits of Shin's declare each one individually 42
and document them precisely indicating the conditions under which each one is strong buy individually 43
it is meant to not take shortcuts like using one super polymorphic exception. 44
That just don't do throws Exception or throws drawable doing this effectively obscure any specific exceptions 45
that may be thrown by the matter. 46
So use specific exceptions rather than generic ones. 47
Know with regards to unchecked exceptions although it is optional. 48
Declare them do document them as carefully as checked exceptions generally majority of untyped exceptions 49
are thrown in the event or pre-conditioned by notions recall that a precondition violation is simply 50
a failure by an A B or client to stick to the contract. 51
If you recall even in our demo we used a precondition check in the Send method unhatched A.P. class 52
. 53
We also documented it. 54
The other Rostok So this way users of them mattered were taken the necessary precautions when passing 55
arguments one important thing the item says is that document unchecked exceptions but do not declare 56
them in the matter declaration mission to disrupt any program or looking at your method to distinguish 57
checked exceptions from unchecked once item also says that it is particularly important to document 58
unchecked exceptions thrown by in defacement there is this where the documentation would be part of 59
this contract and therefore in Ebers common behavior among its different implementations 60
Finally there is also a related item from another chapter in effective Java. 61
It is item 38 on says check barometers for validity. 62
It's a precondition Jecks which we already discussed the item it raises us to think about barometer 63
restrictions when writing new methods or constructor's and if there are any restrictions you need to 64
check them at the beginning of the method and through any unchecked exceptions and also document them 65
as we just discussed here. 66
So that's for public markets but for nonpublic methods it is recommended to do parameter checks using 67
an added feature of java called associates which we will see next so those are some more valuable divs 68
and you should always keep them in your mind. 69
Thank you