1

00:00:01,120  -->  00:00:08,970
Let's not look at the last item which is item 61 and it says throw exceptions it properly to the obstruction

2

00:00:08,980  -->  00:00:09,450
.

3

00:00:09,930  -->  00:00:14,320
So let's go ahead and look at this item in code.

4

00:00:15,360  -->  00:00:21,360
What does item say is that in a multi-year system where we have multiple layers like the higher level

5

00:00:21,360  -->  00:00:23,560
they are under lower level years.

6

00:00:23,790  -->  00:00:27,070
Unbe how higher level methods in working lower level methods.

7

00:00:27,630  -->  00:00:33,960
And if a higher level method catches an exception from a lower level then instead of propagating that

8

00:00:33,960  -->  00:00:40,410
exception it should to a new exception that is more meaningful in terms of higher level abstraction

9

00:00:40,440  -->  00:00:41,150
.

10

00:00:41,590  -->  00:00:48,390
This way higher level layer is not polluted with lower level digger's and this idiom is referred to

11

00:00:48,390  -->  00:00:50,390
as exception translation.

12

00:00:50,680  -->  00:00:56,220
And we have already done exception translation for example here in our API parser class.

13

00:00:56,250  -->  00:01:01,760
If we assume that this is a higher level higher level higher and the lower level layer would be the

14

00:01:01,800  -->  00:01:03,960
partially emitted from the indigent class.

15

00:01:03,960  -->  00:01:08,030
Understanding the number format exception which is a lower level exception.

16

00:01:08,070  -->  00:01:13,830
So here we are catching this exception and in its place we are generating this higher level exception

17

00:01:14,100  -->  00:01:16,260
so that exception translation.

18

00:01:16,320  -->  00:01:18,150
So here an exceptions do em all.

19

00:01:18,220  -->  00:01:22,390
We are just the sheer amateurs if we consider it as as the next higher level.

20

00:01:22,710  -->  00:01:26,370
So it is handling the higher level exception.

21

00:01:26,370  -->  00:01:33,060
Had we not done that and if we had propagated the number format exception then this higher level field

22

00:01:33,090  -->  00:01:39,540
would be polluted with the lower level details like the API like the number format exception and that

23

00:01:39,540  -->  00:01:45,030
would be confusing to anybody viewing this particularly or against somebody if somebody is viewing the

24

00:01:45,030  -->  00:01:49,000
social good it would be confusing to them as it's a higher level layer.

25

00:01:49,020  -->  00:01:49,680
And it's.

26

00:01:49,760  -->  00:01:54,090
And they are looking at some really low level exceptions.

27

00:01:54,300  -->  00:01:56,200
So that would be confusing to them.

28

00:01:56,220  -->  00:01:59,960
So that's basically exception translation.

29

00:02:00,390  -->  00:02:03,530
So that's good but also it should not be are used.

30

00:02:03,540  -->  00:02:09,420
OK so first we should try to prevent the lower level exception itself in this case it's not possible

31

00:02:09,420  -->  00:02:17,040
because it's because of an error from the partners website it's because of that ad done by the partners

32

00:02:17,130  -->  00:02:18,450
or by our partners.

33

00:02:18,480  -->  00:02:20,330
So it's not preventable.

34

00:02:20,550  -->  00:02:23,860
But if it's not preventable we should at least see if it can be handled.

35

00:02:24,060  -->  00:02:24,520
OK.

36

00:02:24,690  -->  00:02:28,710
Now if it cannot also be handled then we can do exception translation.

37

00:02:29,070  -->  00:02:34,330
But in some cases even the lower level exception might be appropriate to higher levels.

38

00:02:34,370  -->  00:02:34,660
OK.

39

00:02:34,680  -->  00:02:40,410
In that case it is fine to propagate them only if it's not possible if they are not appropriate in that

40

00:02:40,590  -->  00:02:41,220
situation.

41

00:02:41,220  -->  00:02:43,820
We can do an exception translation.

42

00:02:44,600  -->  00:02:51,000
No sometimes a programmer debugging the program might want to know the exact cause behind the generation

43

00:02:51,000  -->  00:02:52,950
of the higher level exception.

44

00:02:53,310  -->  00:02:57,810
In this case it would be helpful for the programmer to allow access to the lower level exception.

45

00:02:58,470  -->  00:03:04,100
And this can be done by a special form of exception translation Karla's exception Cheney.

46

00:03:04,680  -->  00:03:06,740
So similar to a detail message.

47

00:03:06,870  -->  00:03:12,220
The higher level exception and can encapsulate the low level exception.

48

00:03:12,420  -->  00:03:15,500
Let's see how that's how that can be done.

49

00:03:15,540  -->  00:03:18,900
So here we have the higher level exception API for matchin exception.

50

00:03:18,930  -->  00:03:21,180
And let's see how we can.

51

00:03:21,180  -->  00:03:23,690
Encapsulate it at a lower level exception.

52

00:03:23,700  -->  00:03:26,270
So let's go back to its class.

53

00:03:26,490  -->  00:03:31,500
Let's add a new parameter of pipe towable.

54

00:03:32,310  -->  00:03:35,260
It's called Just cause it's the right named reuse.

55

00:03:35,340  -->  00:03:39,950
So you might have guessed already that this would be the lower level exception.

56

00:03:39,960  -->  00:03:44,820
Now let's pass it to the constructor.

57

00:03:44,820  -->  00:03:48,240
So here we are in Woking the superclass constructor.

58

00:03:48,240  -->  00:03:51,220
So let's just look at the constructor here.

59

00:03:51,310  -->  00:03:56,330
And you said Jenrette construct some superclass as you can see there is this constructor called which

60

00:03:56,430  -->  00:03:58,720
is taking two parameters one is the daily message.

61

00:03:58,730  -->  00:04:02,150
Another one is the actual costs which would be the low of an exception.

62

00:04:02,280  -->  00:04:03,220
It's a global

63

00:04:06,340  -->  00:04:12,780
it's goodbye to appear here and it's past the lower level exception which is you

64

00:04:15,750  -->  00:04:23,620
know go into exceptions all and just execute this.

65

00:04:23,750  -->  00:04:29,100
So as you can see when we do have Prince diopters on the higher level exception it's printing both the

66

00:04:29,100  -->  00:04:36,090
higher level stackers which is here API format and it's also printing printing the lower level exception

67

00:04:36,400  -->  00:04:37,680
right here.

68

00:04:37,680  -->  00:04:45,960
Now if the programmer wishes to see only the low level exception not the higher level then there is

69

00:04:45,960  -->  00:04:54,030
this method called Get Gause so it can be invoked on the higher level exception which is easier and

70

00:04:54,330  -->  00:04:56,550
so good Cause we're ordered not to doable.

71

00:04:56,730  -->  00:05:02,420
And if we invoke the French doctoress mattered it would render a lower level exception.

72

00:05:02,430  -->  00:05:06,260
So it would just present only the lower overload exhibition as you can see here.

73

00:05:06,990  -->  00:05:14,880
So that's basically exception chinning but in some situations some classes some exception classes might

74

00:05:14,880  -->  00:05:19,820
not have such kind of fat changing over constructor.

75

00:05:20,110  -->  00:05:23,070
So and that is there is a way we can get off.

76

00:05:23,070  -->  00:05:30,150
So let's just remove that little story Muga heart.

77

00:05:32,760  -->  00:05:37,380
Now here there is a method called dot in it cause and we can use that.

78

00:05:37,770  -->  00:05:40,970
But if that were true that would talk through obol.

79

00:05:41,160  -->  00:05:47,690
So in which case this who you know in which case we would have to specify that through obal in the throws

80

00:05:47,700  -->  00:05:53,640
clause and we don't want to do that because we want to try only as specific exceptions as possible.

81

00:05:53,640  -->  00:05:54,480
Right.

82

00:05:54,480  -->  00:05:58,480
So we what we don't want to do something that are generic.

83

00:05:58,620  -->  00:06:04,410
So that's why we will we know we were dig this out from here.

84

00:06:07,130  -->  00:06:12,030
We're in a new statement here.

85

00:06:12,540  -->  00:06:16,350
So create an exception object here let's see event

86

00:06:17,690  -->  00:06:20,630
.

87

00:06:23,810  -->  00:06:30,540
Sorry this needs to be easy and we're just simply throwing even so we are still throwing a higher level

88

00:06:30,540  -->  00:06:31,590
exception.

89

00:06:31,620  -->  00:06:33,140
It's just that it.

90

00:06:33,710  -->  00:06:38,490
We are passing the lower level exception using the in it costs because we don't have the constructor

91

00:06:38,570  -->  00:06:40,620
chaining of a constructor in our class.

92

00:06:40,940  -->  00:06:42,320
So that's it.

93

00:06:42,450  -->  00:06:48,530
Now once again if you go here and if you execute it are you just going to print the costs.

94

00:06:49,470  -->  00:06:51,010
So that's about it.

95

00:06:51,030  -->  00:06:54,360
You can also take a look at the supplementary notes on.

96

00:06:54,360  -->  00:07:00,630
I'm going to include some key points from the item so you can also read the item itself if you have

97

00:07:00,630  -->  00:07:01,050
the book.

98

00:07:01,050  -->  00:07:02,720
Otherwise you can just look at the key points.

99

00:07:02,730  -->  00:07:07,630
Mostly it's just what are we covered here in the class and that's it.

100

00:07:07,680  -->  00:07:08,090
That's it.

101

00:07:08,090  -->  00:07:11,370
I know you can also find updated code in the resources section.

102

00:07:11,550  -->  00:07:12,090
Thank you.

103

00:07:12,100  -->  00:07:12,920
And happy coding
