As mentioned earlier apart from check the captions we also have something called unchecked exceptions 2
. 3
So a program can generate either checked or unchecked exceptions the whole thing check exceptions. 4
But let's do a quick recap of it. 5
We know that there are costs by exception of situations that are simply not under our control. 6
Examples would be things like partners or were being down our database being unavailable. 7
If you do it checked exception the compan I've got on it is two things. 8
First is you must announce that you're throwing the exception by specifying it in the method declaration 9
using a gross gross and second is the invoking code must acknowledge the exception by wrapping the calling 10
card in a cricut rock or just in done really the exception for the next higher level method to handle 11
that next is unshaped exceptions and these are generated by either programming frost or due to some 12
internal system writers like out-of-memory others and if they're caused by programming flaws then they're 13
referred to as the runtime exceptions. 14
But of their culture in general system adder's then they're just referred to as adder's since runtime 15
exceptions are due to programming at all. 16
You want them to happen mostly or double up on testing time. 17
So ideally with good development and testing effort you would want as minimal runtime exceptions as 18
possible. 19
It there's a GBM deleted under normal conditions and they occur rarely and when they do occur the Jell-O 20
program terminates Generally you shouldn't catch on on time exceptions as there are due to programming 21
errors usually the recovery from such exceptions is implausible and continued exaggeration would do 22
more harm than good. 23
But sometimes you might want to catch them too. 24
One example would be when you're parsing a response from a web service you encounter a problem parsing 25
some piece of data. 26
For instance format of a date field might have changed in this because when you try to parse the date 27
field you may get an unchecked exception. 28
So in this case it would be worthwhile to cast the exception and let the web service provider know about 29
it. 30
And of course you should seriously run them not to change their API. 31
And with regards to errors since there are some abnormal conditions a reasonable application would not 32
be expected to catch it. 33
So you would almost never catch an error as the name implies these exceptions are not checked by computer 34
that you can store them anywhere. 35
And the compiler does not bother checking whether or not they are specified in the method declaration 36
or whether or not they are handled by the invoking code. 37
So that's entirely optional if you want to you can specify them in the declaration and you can also 38
handle them but it's not mandatory. 39
And so it is entirely up to you shortly we leave them off unchecked exception. 40
They have to look at runtime exception. 41
We would not look at error as if it is really an abnormal condition and we said we don't want to handle 42
it in almost all cases. 43
But if you'll recall we did just that and out-of-memory error in one of them was in JVM in dentals chapter 44
so at least we have seen an editor being gender Did anyone offered the most on here as exceptions in 45
Hedican street and the route you have trouble plus that is a superclass of all exceptions are Natters 46
and it has to Sampras's exception I never it it crosses represent errors that were just part of unshipped 47
exceptions. 48
No exception class has of surprises on one of them is runtime exception runtime exception under subprocess 49
represent runtime exceptions that are also discussed as part of unshipped exception. 50
As you can see all unshipped exception classes are emphasized in red but all checked exception classes 51
are emphasized in book so checked exceptions are all exceptions that are represented by a label or one 52
of its surprises with the exception of error or runtime exception or one of their surprises. 53
Not get the convention all across all that a person being at odds and with that text editor all of that 54
exception classes acceptable. 55
And with the next exception know this light also illustrates all that commonly uncontained checked and 56
unchecked exceptions. 57
Let's quickly review most of them. 58
We are really not him or them or the Iowa exception which is a checked exception and all its subclasses 59
are related to input output errors like reading from or writing with a missing phone or a server that 60
is not responding and you already know about null pointer I'm at a Nick sort of bonce exceptions both 61
of which are unchecked exceptions a legal argument the exception is an unchecked exception and it is 62
thrown when the method is passed an illegal or an inappropriate argument legal next see this exception 63
in our table Glasgow's exception is an unshipped exception is thrown if it tried to cast an object to 64
suppress but the object is not really an instance of this obvious number for me the exception is thrown 65
if we try to convert a string to a numeric type but the string does not have an appropriate format. 66
For instance we get this exception if we apply integer not parsed in method on a string like ABC next 67
non-class for Nader is an unchecked exception and it is a subclass of error and it is drawn when classloader 68
Kreisler the definition of a class A no definition could be fun. 69
Have a lower class definition existed when the class was compiled. 70
But it can no longer be found for some reason. 71
Finally we already know about out-of-memory error which is a subclass of Woodrell machine at a JVM throws 72
it when it is unable to create an object of insufficient memory. 73
So those are the most commonly encountered check done unshipped exceptions and you can also read more 74
about them from the API. 75
Let people pull up the AP I could just show you where you can find the exceptions. 76
And here is the API I and here are all the packages on how clicked on the dollar package. 77
And here you can see all the interfaces within Jodan package and also all the classes here. 78
If you scroll down at the bottom you can see all the exceptions and also the on the ruler the dollar 79
package has. 80
OK so next let's just go ahead and let's look at the demo of unchecked exception. 81
Could demonstrate an exception. 82
Let's just go to our next hour Senator Vijender I'm unsure that's a option. 83
Illegal argument exception. 84
And as mentioned earlier this exception will be gender if the mother is involved with an illegal argument 85
. 86
For example this method has the parameter destination whose value should be either 0 or 1. 87
Now the sentiment that is in work with any other argument value other than zero on one then it would 88
be illegal. 89
And we can generate an illegal argument exception for that. 90
OK. 91
So many times methods and constructors have such restrictions on the arguments and arguments that are 92
going to be passed on such restrictions on cardless preconditions. 93
And in order to enforce such preconditions we can do some parameter validation at the beginning of the 94
matter. 95
OK. 96
So let's also do that let's also enforce a precondition in cyber if statement here at the beginning 97
of the matter and destination value is either less than zero or greater than one. 98
Let's throw an illegal argument exception 99
and this one is from the July-August Lang package and since it's an unchecked exception you can see 100
that there is no compulsion at all here. 101
So we need not to specify it here but if we want to we can do that. 102
And similarly there is no compulsion at all here. 103
In fact here we have polymorphic types so let's remove that because they will catch that exception. 104
So now we have only two exceptions here and there is no legal argument exception here just fine because 105
it's an unchecked exception so owners just go ahead and document this particular exception because the 106
Klan's hopla know about it. 107
So will say it throws 108
so this exhibition will be generated every destination is less than zero. 109
Our destination is greater than one. 110
So anybody in this method will have to look at this API and they can see that if they pass this kind 111
of a value then it could be considered illegal and an exception will be genitor head knowledge just 112
as umed duck here. 113
The programmer was careless and he did not read the API documentation. 114
Unsensible you off minus one Sananda just go ahead and exude your does. 115
And as you can see an illegal argument exception has been generated. 116
OK. 117
So that's an unchecked exception. 118
And generally we should run out such exceptions because they are programming flaws. 119
And it's not good to catch them so that's about it and that's it. 120
I'm off on two exceptions. 121
Thank you. 122
Happy coding.