Sorry if this trivial to you, I was just wondering what is the difference between both methods; I suppose if the finally field exists it must be able to do something that cant be done outside the try-catch block, but I cant think of a scenario.
Out of curiosity, is there an adnvantage of creating a sequence in the finally field of the try-catch block over creating the sequence after the try-catch block?
@m.landos yes there are advantages.
For example, When we place while loop or for each loop inside the try block, For every input item the finally will be executed irrespective of errors.
In the same case if you place a sequence outside try-catch block then the sequence will be executed only once after completing try-catch activity.
There are advantages…
in a sequence, the tasks are executed in a sequential order. So ideally, you will have to complete the try catch block successfully to do what ever you have after that. The Finally section of the Try Catch block gives you the ability to execute certain tasks even though you end up with errors or not in the try catch block. Think of a status logger… So, in the process, if you want to get the status whether the task was successful or not, The finally section of the try catch block gives you the ability to execute this even it ends up with an error or not…
So, if the logging activity is outside the try catch block, if the try part ends up in an error, the logging activity will not be executed. So that is one advantage of having the Finally section…
Hope it helps!!!
I mean, it is maybe more organized like you say it, but still I feel like putting the try catch and “after-squence” inside the loop is the same outcome.
Thanks, but I’m still with doubts, I mean, will itbe useful when there occurs an exception that is not catched by the try-catch? So if i’m catching every exception that may happen, both finally and post-sequence will be executed and then again finally wouldnt be needed. Or am i still missing something?
Usually the types of errors that are caught by the try catch are:
You can add more if you need so… However, it will not actually catch any business logical errors, errors in different logics have have in place to handle the stuff and things like that. So, basically it catches the system related exceptions. The option System.Exception covers almost all of them… So if any error that falls under these categories, having the Finally section would be helpful because it will not be continuing to the rest of the sequence…
Is that clear enough? If not, let me know will try to explain in a much understandable way