1

00:00:01,160  -->  00:00:08,270
Let's not look at how we can create our own exceptions in the process we will also look at four very

2

00:00:08,270  -->  00:00:15,370
important suggestions from effective giallo unheeded the four items that we are going to discuss and

3

00:00:15,550  -->  00:00:21,890
discuss all these items include we will discuss the first two items in this lesson and the last two

4

00:00:21,890  -->  00:00:29,310
will be discussed in the follow up lessons and the first one is item 58 and it says use checked exceptions

5

00:00:29,430  -->  00:00:35,230
for recoverable conditions on runtime exceptions for programming it has to be under to discuss this

6

00:00:35,240  -->  00:00:35,400
.

7

00:00:35,760  -->  00:00:40,550
But I will discuss it in the context of creating new exception class itself.

8

00:00:41,720  -->  00:00:48,370
Second one is straightforward underdosed items have to fly under sists not to ignore exceptions people

9

00:00:48,370  -->  00:00:56,830
often by late date by using empty Gutch box which defeats the purpose of exceptions items is that ignoring

10

00:00:56,830  -->  00:01:03,120
an exception is similar to ignoring a fire alarm third and fourth items will be discussed later.

11

00:01:03,300  -->  00:01:09,690
And also supplemental notes will include a summary of all main points covering these items.

12

00:01:09,690  -->  00:01:12,750
So let's go ahead and extend no exceptions Democritus

13

00:01:15,370  -->  00:01:22,210
here we are in the Send method within the history class and we know that this method is responsible

14

00:01:22,390  -->  00:01:25,900
for the actual shooting of the data with the partner.

15

00:01:26,140  -->  00:01:31,270
And there are two ways to do it and we would be focusing on the second approach which is to pass the

16

00:01:31,270  -->  00:01:35,120
data in a pragmatic way via web service.

17

00:01:35,380  -->  00:01:40,930
And that happens if destination is equal to one and did a couple of genius to be made here and this

18

00:01:40,950  -->  00:01:44,050
method one off them as the data type here.

19

00:01:44,150  -->  00:01:47,520
Often there is a recurrent type has been changed from white to string.

20

00:01:47,530  -->  00:01:52,520
And the reason for that is we just want it done the response that we get from the web service.

21

00:01:52,840  -->  00:01:58,390
So the reps overstates the take somebody doesn't put a target and some response OK.

22

00:01:58,450  -->  00:02:02,020
Like whether it's whether that data has been processed successfully or not.

23

00:02:02,200  -->  00:02:06,090
And we just want to pretend that the doctor does to the working mother.

24

00:02:06,310  -->  00:02:11,500
So here is one variable the variable which which is going to read and the value of it is initial estimates

25

00:02:11,500  -->  00:02:18,430
success and it is really initialized here hear the response that we get from the web service.

26

00:02:18,430  -->  00:02:23,380
Now we're not doing the actual web service interrogation so let's just assume that this is the response

27

00:02:23,380  -->  00:02:24,920
that we got from the service.

28

00:02:24,920  -->  00:02:25,290
OK.

29

00:02:25,450  -->  00:02:26,910
So it's an example response.

30

00:02:27,310  -->  00:02:33,460
And here is the root element which is it isn't and within that we have court and within court there

31

00:02:33,460  -->  00:02:35,180
is this value I call success.

32

00:02:35,300  -->  00:02:42,880
OK now let's assume that according to the API contract exhumed this was supposed to be a numeric value

33

00:02:43,190  -->  00:02:48,820
Rexy all these days it was you know Mark uncertainly at this point of time when we made the invocation

34

00:02:49,380  -->  00:02:52,490
did attend and non-numeric value string.

35

00:02:52,580  -->  00:02:53,100
OK.

36

00:02:53,200  -->  00:03:00,280
So basically they broke the API contract and this is done going to affect us as it really big our court

37

00:03:00,280  -->  00:03:01,180
also.

38

00:03:01,310  -->  00:03:09,970
So they shouldn't have done this but trust me in my experience with several teams usually most of the

39

00:03:09,970  -->  00:03:11,020
time they don't.

40

00:03:11,170  -->  00:03:16,250
Most of the teams that I work with they never change the API in this way.

41

00:03:16,540  -->  00:03:22,260
But sometimes there were beams which did change the API that broke the cord that broke my cord.

42

00:03:22,420  -->  00:03:24,490
So it can happen sometimes.

43

00:03:24,490  -->  00:03:27,720
So that's when you're working with some unprofessional diems.

44

00:03:27,970  -->  00:03:30,460
So you shouldn't be doing that.

45

00:03:30,490  -->  00:03:35,800
So once the API is out you shouldn't change the response or even the request format.

46

00:03:35,860  -->  00:03:41,680
So in case you want to change it you have to let your clients know in advance and or set two or three

47

00:03:41,680  -->  00:03:47,180
weeks in advance so that they can make the necessary adjustments.

48

00:03:47,470  -->  00:03:52,010
So if you're doing something you don't amend just don't change the API Midway.

49

00:03:52,090  -->  00:03:56,200
Just make sure that your clients are informed in advance.

50

00:03:56,440  -->  00:03:59,150
So here is their response and we are reading the response here.

51

00:03:59,200  -->  00:04:03,900
Let's go back to exceptions to all this is a shared method from where we are in Woking.

52

00:04:04,090  -->  00:04:05,330
So here is the response.

53

00:04:05,350  -->  00:04:07,570
So it's getting assigned to this response variable.

54

00:04:08,600  -->  00:04:10,090
A new class has been written.

55

00:04:10,180  -->  00:04:16,420
API parser it's responsible for parsing the response on extracting individual data from it.

56

00:04:16,500  -->  00:04:20,450
So it's a different component here and there is a new method within that.

57

00:04:20,490  -->  00:04:23,000
It's Carlos parse send response code.

58

00:04:23,040  -->  00:04:26,370
So it's going to take the response here as an in book.

59

00:04:26,520  -->  00:04:30,080
It's going to extract the value of the code element.

60

00:04:30,200  -->  00:04:30,440
OK.

61

00:04:30,450  -->  00:04:33,710
So there wasn't anyone called court and it's going to extract that.

62

00:04:33,980  -->  00:04:36,060
And you're also passing these two values.

63

00:04:36,060  -->  00:04:39,420
Hello Aaron goodness which one also passed here to the Send method.

64

00:04:39,660  -->  00:04:41,980
And literally will see why we need that.

65

00:04:42,300  -->  00:04:42,530
OK.

66

00:04:42,540  -->  00:04:45,200
So let's just going do this mattered here.

67

00:04:46,490  -->  00:04:47,170
Here it is.

68

00:04:47,300  -->  00:04:51,200
So this matter is going to return the actual response.

69

00:04:51,220  -->  00:04:54,620
OK so it's going since it's supposed to be a numeric value.

70

00:04:54,620  -->  00:04:56,280
So it's going to return.

71

00:04:56,400  -->  00:04:59,350
And here so it's initialized or minus one.

72

00:04:59,350  -->  00:05:04,330
And here is a card which is going to extract the the value off the code element.

73

00:05:04,430  -->  00:05:04,670
OK.

74

00:05:04,670  -->  00:05:07,520
So just don't worry about it you can look at it later.

75

00:05:07,700  -->  00:05:12,580
But all it is doing is it is going to extract the code on in order to extract the code.

76

00:05:12,590  -->  00:05:19,240
I mean it has it does extract extracting court but in order to convert it to and we are using the parse

77

00:05:19,240  -->  00:05:21,490
and matured from the entire class.

78

00:05:21,710  -->  00:05:27,120
Now this is going to generate an exception because the value is non-numeric right.

79

00:05:27,130  -->  00:05:34,010
No because they have changed the API response but since we are a professional quarters we have a cricut

80

00:05:34,010  -->  00:05:34,770
Sheir.

81

00:05:35,120  -->  00:05:36,770
We want to because we want to handle it.

82

00:05:36,770  -->  00:05:42,450
So let's bring it here it's printable you and it's going to give us an exception.

83

00:05:45,480  -->  00:05:50,570
As you can see it says Number four marked exception because the input string is success.

84

00:05:51,730  -->  00:05:54,150
So it has been broken not so now.

85

00:05:55,500  -->  00:06:01,820
Let's create a new exception and throw that exception here so on later I will explain why.

86

00:06:01,950  -->  00:06:03,870
Why do we need to create a new exception.

87

00:06:03,870  -->  00:06:09,470
Why not simply propagate this exception so that will be disclosed in a later lesson which is also it

88

00:06:09,490  -->  00:06:13,970
which basically is about one of the items that we are supposed to discuss.

89

00:06:14,220  -->  00:06:21,960
So let's just go ahead and create a new exception since it's going to be an exception type of exception

90

00:06:21,960  -->  00:06:22,120
.

91

00:06:22,230  -->  00:06:25,300
So it has to extend one of the exception classes.

92

00:06:25,320  -->  00:06:25,680
Right.

93

00:06:25,680  -->  00:06:29,960
So let's just go ahead and do that since the API has changed.

94

00:06:30,030  -->  00:06:41,880
Let's name the exception in a meaningful way and let's call it as API for might change exception.

95

00:06:44,190  -->  00:06:51,300
Not we are going to look at a couple of suggestions from item 58 which is about you know would suggest

96

00:06:51,300  -->  00:06:58,730
that we need to use checked exceptions if you want to recover from the exception or runtime exceptions

97

00:06:58,750  -->  00:06:58,860
.

98

00:06:58,970  -->  00:07:05,580
And if it isn't programming programming it or know we can do we can do an extra here.

99

00:07:05,600  -->  00:07:07,500
Now we can also extend another.

100

00:07:07,680  -->  00:07:12,580
But the item is that we should not extend or we should not subclass it.

101

00:07:12,700  -->  00:07:19,420
And that's because there is a strong convention that errors should be generated only by JVM because

102

00:07:19,420  -->  00:07:20,530
they are JVM related.

103

00:07:20,530  -->  00:07:22,420
Under normal conditions.

104

00:07:22,420  -->  00:07:25,640
So the items are just that we should not be doing that.

105

00:07:26,080  -->  00:07:29,080
We should not be extending that ours.

106

00:07:29,200  -->  00:07:33,580
So there's a strong convention for that if you want to you can do it but we shouldn't be doing it.

107

00:07:33,610  -->  00:07:37,060
And that's that's the recommendation from the item now.

108

00:07:37,060  -->  00:07:40,140
So if this is all good then we can do it on time exception.

109

00:07:40,150  -->  00:07:41,510
That's one thing we can do.

110

00:07:41,560  -->  00:07:46,140
In fact you might want to do that because this is a programming error.

111

00:07:46,660  -->  00:07:49,440
The program is not written you know.

112

00:07:49,540  -->  00:07:52,220
He hasn't doubled up this particular piece of art.

113

00:07:52,270  -->  00:07:59,080
It's coming from an extra source but still you know it's kind of it's kind of a different component

114

00:07:59,080  -->  00:08:04,660
even though it's a different satirise from an extra partner you can think of it as a different component

115

00:08:04,660  -->  00:08:05,350
.

116

00:08:05,350  -->  00:08:11,920
And so it's basically you have to be a programming error from though from somebody in the partner site

117

00:08:12,580  -->  00:08:14,260
so it can be an exception.

118

00:08:14,380  -->  00:08:20,480
But the thing is in this particular case I think it would make sense to make it that checked exception

119

00:08:20,500  -->  00:08:25,750
in because runtime exception is an unchecked exception on by making a checked exception by throwing

120

00:08:25,750  -->  00:08:27,210
a check the exception.

121

00:08:27,300  -->  00:08:34,540
Are going to force the code that is going to invoke this particular method to handle it for sure.

122

00:08:34,550  -->  00:08:35,110
Right.

123

00:08:35,170  -->  00:08:37,130
So that's what will happen.

124

00:08:38,670  -->  00:08:46,080
If we make it a checked exception and the benefit of that is decline here and the exceptions to we'll

125

00:08:46,080  -->  00:08:52,450
have to catch it and let's say if in the future if there is another developer who for whatever reason

126

00:08:52,500  -->  00:08:52,680
.

127

00:08:52,980  -->  00:08:59,190
If you delete that Gorder then the compiler will inform him that they need to provide an exception handling

128

00:08:59,190  -->  00:08:59,870
core.

129

00:09:00,270  -->  00:09:06,960
And if it is a runtime exception since it would be an unchecked exception the compiler will not force

130

00:09:06,960  -->  00:09:07,910
them to do it.

131

00:09:08,010  -->  00:09:15,150
So it makes sense to force the hour hour hour and a person to actually handle that exception.

132

00:09:15,270  -->  00:09:20,940
And the way they can handle it is either by e-mailing the system administrator or one of their own uppers

133

00:09:21,390  -->  00:09:27,150
so that they can take some action they can inform the partner team that they need to fix the API.

134

00:09:27,510  -->  00:09:30,990
So it makes sense to to make this an exception.

135

00:09:31,120  -->  00:09:33,830
And if you want to make it a checked exception it cannot.

136

00:09:33,900  -->  00:09:42,030
We cannot subclass an exception or we cannot subclass error so we can either subclass an exception or

137

00:09:42,030  -->  00:09:46,180
any of its applauses or we can subclass tol'able.

138

00:09:46,410  -->  00:09:50,860
But the item also says that it's not recommended to extend to all.

139

00:09:50,920  -->  00:09:51,250
OK.

140

00:09:51,270  -->  00:09:53,840
So there definitely to indict them definitely recommends that.

141

00:09:54,000  -->  00:09:58,290
And the reason for that is it's just a little bit more confusing for the users.

142

00:09:58,500  -->  00:10:05,010
So they suggested that if you want to extend if you want to create a checked exception you can either

143

00:10:05,530  -->  00:10:11,870
subclause exception class which is their direct subclass of the open or one off it's subclasses one

144

00:10:11,940  -->  00:10:13,940
of the exception classes subprocess.

145

00:10:13,980  -->  00:10:17,170
So let's just go ahead and extend this.

146

00:10:17,280  -->  00:10:18,650
So that's all we have here.

147

00:10:25,760  -->  00:10:35,070
So not to go on as you know this needs to go in that cross-class So those are the those are some suggestions

148

00:10:35,070  -->  00:10:36,450
from item 58.

149

00:10:36,780  -->  00:10:42,470
So here it's go back into exceptions Demel we have an exception here because we need to handle it now

150

00:10:42,490  -->  00:10:42,550
.

151

00:10:42,630  -->  00:10:44,450
So there is already some quarter done here

152

00:10:50,960  -->  00:10:52,610
so it needs to be hundred.

153

00:10:53,000  -->  00:11:00,710
But a lot of times people also just how much blogs so they ignore the exception are an item fifty sixty

154

00:11:00,710  -->  00:11:02,530
five say is that we should not do that.

155

00:11:02,530  -->  00:11:04,540
Don't ignore the exceptions.

156

00:11:04,790  -->  00:11:11,180
Because here around here there is you know is making a statement that you need to handle it.

157

00:11:11,370  -->  00:11:15,650
And if you haven't time to catch block then you're defeating the purpose.

158

00:11:15,950  -->  00:11:21,860
And the item says that if if an exception if you're ignoring an exception like ignoring gun fired not

159

00:11:21,900  -->  00:11:28,940
him so you shouldn't be doing that because even if you ignore it sometimes you may be fined many times

160

00:11:28,940  -->  00:11:32,280
you may be fined but sometimes the results can be disastrous.

161

00:11:32,330  -->  00:11:35,750
Sometimes the results may not be immediately evident.

162

00:11:35,750  -->  00:11:42,890
Maybe the error might happen you know at a later point or find some other kind of gold under time it

163

00:11:42,890  -->  00:11:49,190
might be difficult to figure out the actual reason why the exception has been thrown because it's on

164

00:11:49,310  -->  00:11:52,280
it's happening at a completely different location.

165

00:11:52,440  -->  00:11:53,660
OK.

166

00:11:54,590  -->  00:11:59,780
So you shouldn't be ignoring exceptions with them to catch blocks and even if you want to do that at

167

00:11:59,780  -->  00:12:06,230
least you need to put some kind of a comment here stating why you are why you are not handling it why

168

00:12:06,230  -->  00:12:07,740
it is an empty catch block.

169

00:12:07,850  -->  00:12:18,240
OK so now let's just go ahead and let me also him this uncommented executer as you can see it says an

170

00:12:18,270  -->  00:12:22,330
API for matching exception and gives to doctoress.

171

00:12:22,500  -->  00:12:24,110
So those are the two items.

172

00:12:24,260  -->  00:12:26,590
Item 65 1958.

173

00:12:27,030  -->  00:12:29,470
Next we will look at item 63.

174

00:12:29,530  -->  00:12:32,350
And here we have this stack grease.

175

00:12:32,520  -->  00:12:39,440
But sometimes the issue is not reproducible so it will be difficult for the programmer to fix it.

176

00:12:39,780  -->  00:12:42,820
So item 63 is about how we can address doc.

177

00:12:42,920  -->  00:12:43,640
OK.

178

00:12:43,650  -->  00:12:47,300
So that's important and I'll see you in the next lesson.

179

00:12:47,310  -->  00:12:48,290
Item 63.

180

00:12:48,420  -->  00:12:49,060
Thank you.
