1

00:00:01,170  -->  00:00:06,870
Let's not continue without them all earlier we have seen how an exception can be generated on how it

2

00:00:06,870  -->  00:00:14,620
can be handled it's not on a couple of more things first is about having more than one exception in

3

00:00:14,620  -->  00:00:15,710
the last.

4

00:00:16,000  -->  00:00:16,570
OK.

5

00:00:16,570  -->  00:00:18,670
So trust Roesgen how multiple exceptions.

6

00:00:18,700  -->  00:00:19,950
So we will look at that.

7

00:00:20,140  -->  00:00:23,560
And the second is that an exception object can be referenced.

8

00:00:23,560  -->  00:00:24,690
Polymorphically.

9

00:00:24,840  -->  00:00:26,230
OK that's possible.

10

00:00:26,260  -->  00:00:29,120
And that's because an exception is basically an object.

11

00:00:29,220  -->  00:00:29,550
OK.

12

00:00:29,560  -->  00:00:31,390
So we will also look at.

13

00:00:31,840  -->  00:00:34,520
So let's just go ahead and extend the cord.

14

00:00:36,630  -->  00:00:44,180
Destination is equal to one so we said that if destination is Vaun it means that we want to pass the

15

00:00:44,180  -->  00:00:47,080
date up programmatically to the park nursery.

16

00:00:47,110  -->  00:00:48,610
So it's OK.

17

00:00:48,790  -->  00:00:50,470
So that's what we're going to do.

18

00:00:50,530  -->  00:00:57,510
And if the partnership is done that is it is unreachable then it would throw an exception called us

19

00:00:57,610  -->  00:01:03,580
Iowa exception OK which is also from the Gelada art IO package even file not found exception was from

20

00:01:03,580  -->  00:01:08,130
the Java dot IO package but that's an exceptional situation.

21

00:01:08,380  -->  00:01:10,780
Typically you don't have so much going on often.

22

00:01:10,810  -->  00:01:12,430
So that's an exceptional situation.

23

00:01:12,460  -->  00:01:15,850
And when that happens we need to raise an exception.

24

00:01:15,850  -->  00:01:21,480
So let's just do that let's just throw new your exception.

25

00:01:21,820  -->  00:01:22,330
OK.

26

00:01:22,570  -->  00:01:31,080
Now we need to import this Naga second exception as we know that it needs to be mentioned here.

27

00:01:31,080  -->  00:01:41,600
So let's have it here be a good Let's go back here to exceptions Demel now send mattered also needs

28

00:01:41,600  -->  00:01:43,520
to handle that exception.

29

00:01:43,520  -->  00:01:50,750
OK so when behavior it shows four options let's pick the second one which says I got glass to surrounding

30

00:01:50,910  -->  00:01:54,450
you so there is a song on and try on we want to get Gutch glossier.

31

00:01:54,800  -->  00:01:58,870
OK let's do the now and start off here.

32

00:01:58,870  -->  00:02:00,940
So we have Iowa exception now.

33

00:02:00,940  -->  00:02:02,720
So let's put a print statement here.

34

00:02:03,950  -->  00:02:08,620
Because in the catch block we are going to how exception handling code.

35

00:02:08,770  -->  00:02:12,730
And for now this is our exception handling course so this is how we recover.

36

00:02:13,640  -->  00:02:17,440
Saw this you are just saying connecting to a different server.

37

00:02:17,440  -->  00:02:20,590
Ok so that's how we're going to recover from this exception.

38

00:02:20,710  -->  00:02:23,130
So let's just go hard and change this to one here.

39

00:02:24,250  -->  00:02:25,870
Now and it's just you're on it.

40

00:02:27,840  -->  00:02:33,960
So we are inside main inside share inside San and then an exception was generated and then we and then

41

00:02:33,960  -->  00:02:39,030
the controller came here into Iowa exception under sprinting connecting to a different server.

42

00:02:39,300  -->  00:02:44,540
And once that is done and share is printed on this particular matter has popped off the stock.

43

00:02:44,730  -->  00:02:47,350
And then finally and off Manus Bernard Here.

44

00:02:48,150  -->  00:02:50,390
So that's multiple exceptions.

45

00:02:50,700  -->  00:02:53,540
So you can have it within the glass you can have multiple exceptions.

46

00:02:53,550  -->  00:02:54,990
So that's the first thing.

47

00:02:55,090  -->  00:03:00,600
And the second thing is so we know how we know how to objects here exception objects are the exception

48

00:03:00,660  -->  00:03:03,220
objects can be referenced polymorphically.

49

00:03:03,450  -->  00:03:09,220
Now in this case file not an exception is actually a supperless off Iowa exception.

50

00:03:09,550  -->  00:03:10,310
OK.

51

00:03:10,720  -->  00:03:15,320
So file not for an exception can be referenced using IO exception.

52

00:03:15,420  -->  00:03:16,500
OK so that's possible.

53

00:03:16,500  -->  00:03:22,260
So we are going to reference it polymorphically on what that means is we don't need both of them here

54

00:03:22,350  -->  00:03:28,590
so we can just remove this year and it will be polymorphically referenced by Iowa exception so you don't

55

00:03:28,590  -->  00:03:30,420
see any compilation error.

56

00:03:30,420  -->  00:03:32,290
Now the same can be done here also.

57

00:03:32,310  -->  00:03:34,990
So we don't need to catch blocks here.

58

00:03:35,280  -->  00:03:44,590
So that's just common default and let's change it back to zero soil file not for an exception is done

59

00:03:44,620  -->  00:03:51,670
record but it will be caught inside an exception handler which has no exception.

60

00:03:51,760  -->  00:04:00,170
OK so let's just go ahead and run this now you can see that we are inside this exception Rocklynne file

61

00:04:00,200  -->  00:04:02,610
not for an exception has been generated.

62

00:04:02,750  -->  00:04:07,070
It's generated because we are passing zero but we shouldn't be doing this often.

63

00:04:07,120  -->  00:04:11,020
In this case we shouldn't be doing it because you'll see it's a file not found exception.

64

00:04:11,020  -->  00:04:14,850
Unbe are saying that we are going to get a different server.

65

00:04:14,870  -->  00:04:18,790
So the court has to be specific defined not for an exception.

66

00:04:18,790  -->  00:04:19,670
So in this case.

67

00:04:19,970  -->  00:04:27,220
But I like ception objects and I find not for exceptions both of them have the same put it over the

68

00:04:27,240  -->  00:04:29,340
court and we don't want to do that.

69

00:04:29,410  -->  00:04:30,770
So sometimes it is fine.

70

00:04:30,790  -->  00:04:35,560
But generally you would want to how specific to cover the court.

71

00:04:35,590  -->  00:04:37,790
So let's just change it back here.

72

00:04:39,010  -->  00:04:49,010
So this is how it needs to be k so that very well how specific error handling Goertz not and another

73

00:04:49,020  -->  00:04:52,980
thing is here file not found exception is a subclass of this.

74

00:04:53,100  -->  00:05:01,530
So these exception handlers should be placed from Subclass to words superclass So if a subclass exception

75

00:05:01,530  -->  00:05:04,540
handler should come before a gross exception handler.

76

00:05:04,560  -->  00:05:06,270
Otherwise we get a compiler that.

77

00:05:06,420  -->  00:05:14,820
Let's actually try that k now you'll see that as a compilation error on it says unreachable catch block

78

00:05:14,820  -->  00:05:16,330
for filing for an exception.

79

00:05:16,410  -->  00:05:20,050
It is already hundred by the catch block for Iowa exception.

80

00:05:20,550  -->  00:05:21,620
So you cannot do that.

81

00:05:21,660  -->  00:05:24,540
So let's just say control-C.

82

00:05:24,690  -->  00:05:26,090
So this is how it should be.

83

00:05:26,340  -->  00:05:30,930
And so that's about polymorphically referencing them.

84

00:05:30,990  -->  00:05:37,660
Now you can also how other exceptions like for example both fighting not for an exception are no exception

85

00:05:38,700  -->  00:05:48,170
are subclasses of this classical exception so you can also have dark and exception is actually a direct

86

00:05:48,170  -->  00:05:49,570
supperless of true love.

87

00:05:49,580  -->  00:05:51,470
So you can also have trouble here.

88

00:05:52,690  -->  00:05:55,090
So both of these are possible.

89

00:05:55,340  -->  00:05:58,520
OK so you can do that.

90

00:05:58,760  -->  00:06:05,330
So that's all because off exception objects can be referenced polymorphically as an exception an exception

91

00:06:05,330  -->  00:06:06,900
is basically an object.

92

00:06:07,020  -->  00:06:07,870
OK.

93

00:06:07,890  -->  00:06:12,300
And another thing is we said that it goes from subclassed to supercross here.

94

00:06:12,710  -->  00:06:15,670
But let's say if the exceptions are siblings.

95

00:06:16,040  -->  00:06:21,980
As long as they don't how would the exception clauses do not have a superclass oppressive relationship

96

00:06:21,980  -->  00:06:22,140
.

97

00:06:22,220  -->  00:06:25,160
Then we could we can have them in any order.

98

00:06:25,250  -->  00:06:26,030
OK.

99

00:06:26,030  -->  00:06:30,470
Only thing is if they have a supercross up close relationship on it only then the supperless should

100

00:06:30,470  -->  00:06:31,950
come before supercross.

101

00:06:32,030  -->  00:06:38,660
OK so as long as it's within the exception inheritance tree that starts with the Crucible as long as

102

00:06:38,660  -->  00:06:44,320
they are not in the same inheritance but we are good so they can be in any in any order.

103

00:06:44,750  -->  00:06:47,030
And so that's about it.

104

00:06:47,170  -->  00:06:52,610
Now the cool thing about this whole exception handling mechanism is all you are exception and exception

105

00:06:52,610  -->  00:06:54,360
handling code is one place.

106

00:06:54,460  -->  00:07:00,140
OK so you don't it's not scattered across the hall and outsource scored and then a class.

107

00:07:00,140  -->  00:07:05,070
So it's all in one place of Fard you know for the gross statements.

108

00:07:05,300  -->  00:07:11,510
So you can you can always you know with a quick glance you can you you know what kind of exceptions

109

00:07:11,510  -->  00:07:12,640
can be generated.

110

00:07:12,720  -->  00:07:14,430
OK so that's one nice thing.

111

00:07:14,450  -->  00:07:19,800
And the second thing is compiler is actually forcing us to handle the exceptions.

112

00:07:19,930  -->  00:07:20,320
OK.

113

00:07:20,320  -->  00:07:27,100
And it is not making the programmer to handle it as an afterthought if it is like an afterthought.

114

00:07:27,170  -->  00:07:33,980
Then the programmer would be lazy and really not might and most likely not provide the exception handling

115

00:07:33,980  -->  00:07:36,620
code because he or she might forget about it.

116

00:07:36,770  -->  00:07:40,340
So that that would lead to for a trial record.

117

00:07:40,520  -->  00:07:45,950
So because handling except exceptions is basically an exception in situations happen in exceptional

118

00:07:45,950  -->  00:07:48,810
situations on computer wants us to handle it.

119

00:07:48,880  -->  00:07:49,240
OK.

120

00:07:49,340  -->  00:07:52,590
Now sometimes programmers how something like this.

121

00:07:52,640  -->  00:07:58,670
Normally it is by convention a lot of people use only exception procedure but it is.

122

00:07:58,740  -->  00:08:03,440
But as we mentioned earlier we need better re how specific exception process.

123

00:08:03,770  -->  00:08:10,870
But when they do how sometimes they're just don't provide any body within the catch block you know they're

124

00:08:10,910  -->  00:08:13,550
just how empty balances on that is also not good.

125

00:08:13,730  -->  00:08:18,400
So so in a way you're kind of cheating it cheating the compiler itself.

126

00:08:18,440  -->  00:08:19,360
So that's not good.

127

00:08:19,460  -->  00:08:25,010
And there is an item specific to that it would be to look at that later but it mainly says that we need

128

00:08:25,010  -->  00:08:29,010
to have some kind of audit already called but we will look at that item later.

129

00:08:29,060  -->  00:08:35,350
So the compiler is basically checking that the truest clause includes the exceptions here.

130

00:08:35,570  -->  00:08:40,280
If you have some kind of a troll statement here if you're throwing some exceptions it is ensuring that

131

00:08:40,280  -->  00:08:45,970
we how it checks that it checks that the exception is specified here in their declaration.

132

00:08:45,990  -->  00:08:49,910
And it also checks that the exception is caught somewhere.

133

00:08:50,000  -->  00:08:50,210
OK.

134

00:08:50,210  -->  00:08:51,780
So there is an exception handler.

135

00:08:51,830  -->  00:08:56,280
So it's going to check it's going to do that kind of a checking for these exceptions.

136

00:08:56,450  -->  00:09:02,780
And for that reason all these exception classes are referred to as checked exceptions as they're being

137

00:09:02,780  -->  00:09:04,600
checked by the compiler.

138

00:09:04,910  -->  00:09:11,310
So what that means is there are also other types of exceptions which are not checked by compiler.

139

00:09:11,330  -->  00:09:16,730
So which means that you can throw an exception but you need not specified them in the declaration.

140

00:09:16,730  -->  00:09:18,940
Similarly you need not catch them also.

141

00:09:18,950  -->  00:09:22,440
So there is no option on it to catch them.

142

00:09:22,460  -->  00:09:27,710
So those are all different types of exceptions on there since they're not being checked by the compiler

143

00:09:28,040  -->  00:09:30,200
that cardless unchecked exceptions.

144

00:09:30,320  -->  00:09:30,910
OK.

145

00:09:31,150  -->  00:09:34,580
Undoctored that is something that we would look at in the next lesson.

146

00:09:34,580  -->  00:09:34,960
OK.

147

00:09:35,090  -->  00:09:36,680
So that's about it for now.

148

00:09:36,770  -->  00:09:37,330
Thank you.

149

00:09:37,350  -->  00:09:39,830
And happy coding and I'll see you in the next lesson.
