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