Not look at specific sections in the last lesson when we did them or at the very end we already looked 2
at the supplement exceptions. 3
Did the supplement exceptions work they can get off automatically by the try with resources Sendak's 4
. 5
So we were generating a one exception in the try block and the message was important exception. 6
So this was the main exception that was being generated by this method called file copy with under exceptions 7
that were being generated by these resources B and B do were embedded within what encapsulated within 8
this exception I suppressed exceptions and we said that if we do not use private resources and data 9
about if we use only try and finally Bross strike and finally block then only the exception the first 10
exception that gets generated in the final block which would be one of these two would be to end by 11
this method. 12
I and the other two exceptions one is this one on one of them would be one of these. 13
So both those exceptions will be ignored. 14
So it be masked it's Carlos acception masking. 15
And we said that we need to fix it manually. 16
So that's what we are going to do here. 17
So it's a continuation of their demo from the previous lesson. 18
So there we had a file copy with him and we introduced two more matters on just one as file copy we 19
thought. 20
Which means that we are not using private resources syntax. 21
So there is no automatic resource management. 22
So it's just the same code. 23
So since it is old fashioned try block so all the resources are declared outside and they're initialized 24
inside the try block on everything else is seen we have generating that exception and then the finally 25
block we are closing down resources. 26
So we have this not clean looking court. 27
So that's what we have. 28
And in the main method we are again invoking this new method file copy we don't. 29
So let me just read this. 30
And as you can see only trivial exception to is being generated here. 31
That's because that's the first exception that is getting generated here do. 32
So that's the goes across. 33
Throws the trivial exception to an exception and an important exception are simply are simply ignored 34
. 35
Ok so now to fix that we have this new method called Find copy we talked to. 36
I just named or just do. 37
Because you know it's kind of a solution that wasn't being offered as we should do. 38
And we're hundred is handling exception masking biasa operation. 39
So we are going to see how how the remaining two exceptions can be can be suppressed under and not suppressed 40
in fact we want to just throw only this exception important exception like in the case of we three social 41
Sendak's and the other two exceptions have to be suppressed exceptions within this exception. 42
So for this it's just the same court but we're introducing this variable. 43
Qualis Iowa exception it's a local variable and it is off by Aiwa exception. 44
Now we have the tri block so in the earlier version there is only the trial and finally no catch block 45
. 46
But in this matter we also have the catch block. 47
So when this gets executor distro motard gets ex-secret or die. 48
The exception is generated with important exception so that gets caught here in this catch block and 49
we're assigning this variable E to Iowa exception since Aiwa exception variable is also off by no exception 50
. 51
And then in the finally block here is how the resources acros we just check if Aiwa exception is not 52
equal to. 53
Let's say if I were exception was not generator. 54
Then we go into the Alce block and we simply check if we do which is a first resource for does not equal 55
to not for does not equal under it to be closed. 56
But here on Aiwa exception was already generated. 57
That is an important exception got generated and then we go inside and we once again do a check if B 58
does not equal to none other. 59
If it is not equal or not we close it. 60
But if it also if the class met since the close method generates an exception we go into the catch block 61
here and we added as in suppresive exception to the Aiwa exception which already got generated which 62
is the important exception and could do that we have this new method and suppressed which is also part 63
of the towable class. 64
So it was also introduced in Java 7. 65
But f here if Nuckols not look as if an important exception was not generated. 66
So we will go into the else block and we are actually close indeed do. 67
But if we do all since the two genders this exception then it could be caught here. 68
And that exception will be directly assigned to Aiwa exception. 69
That's because Aiwa exception is being generated for the first time. 70
Now we need to also close the second mix of even though D2 throws an exception. 71
We still have to close other resources. 72
Otherwise Bill Haggarty Sosnik. 73
So we go here we just again check Aiwa exception is not equal to null and this definitely could be not 74
equal to null because not even the close method is throwing an exception. 75
Of course another important exception is also being generated. 76
So anyway it's just the same court only thing is being replaced by a deal with repellers might be here 77
. 78
So if there is an exception we go here and we check if B if we invoke disclose method here. 79
And also gender's an exception. 80
Once again we had we captured and we added to the main exception to the IWA exception. 81
Otherwise we go into the old sloop and we just do this. 82
We check if I mean Wilco's method and if it throws an exception we assign it to the Aiwa exception. 83
Q So that's the first time that Aiwa exception is getting generated. 84
Now the same thing is done for in resource and for the open source sensus the last resort. 85
Once again we have the if else block. 86
If I were the exception is not equal to invoke Glos method. 87
And B if it throws an exception we catch it and we added to the Aiwa exception and then we threw the 88
Iowa exception. 89
So that's the exception that's getting thrown by this method. 90
Now if that's not the case. 91
So if I were exception our variable is not assigned a value so far which means no exception has been 92
generated so far. 93
Then we go into the envelope and we close up our true source. 94
And if this is an exception then that would be the only exception that gets generated. 95
So that is it. 96
So let me just go ahead and run this. 97
Make it two here 98
and here you go. 99
So now that is no more exception masking what we have is so pleasant exception on that as it looks exactly 100
identical to the way we had four when we when we were using the tried with resource index. 101
So you have that true somewhat as exceptions which are the trivial exceptions and the main exception 102
is the important exception. 103
OK so as you can see we have to write all of discord to get office of exceptions and private resources 104
and Datsuns automatically handling all of this. 105
So that's the nice thing about that. 106
But Drive-Thru sources of Sendak's specific do only resources if you're not using recloser resources 107
then you have to go get try finally block. 108
So that's about it. 109
Thank you. 110
And happy coding on this new class will also be uploader to the resources section resources section