Hi friends,
I am currently writing a script that reads and writes files.
I would like to handle the possible I/O errors,
but the doc isn't clear to me regarding wether I should use Try/Catch or OnError().
And more generally, what is the difference between the two? And when to use one or the other?
Thank you!
What is the difference between Try/Catch and OnError()? When to use one or the other?
Re: What is the difference between Try/Catch and OnError()? When to use one or the other?
Hi boiler,
That's a good point, thank you.
But let's say I put the whole code of my function in a huge Try/Catch.
What would be the difference with using OnError() then?
That's a good point, thank you.
But let's say I put the whole code of my function in a huge Try/Catch.
What would be the difference with using OnError() then?
Re: What is the difference between Try/Catch and OnError()? When to use one or the other?
u can have multiple OnError() handlers active at a time
an OnError() handler can decide whether to proceed running the thread or exit it once a thrown exception has been emitted
in v1 specifically(not the case in v2), most built-in commands dont throw exceptions unless ran inside a try-block(and even so u have to actually check with the docs whether they do), so ur OnError() handlers wont ever get triggered
the huge Try/Catch wouldnt allow u, for example if u wrapped 5 commands and the 2nd one threw, to proceed with the execution from the 3rd after doing something in the Catch-block
an OnError() handler can decide whether to proceed running the thread or exit it once a thrown exception has been emitted
in v1 specifically(not the case in v2), most built-in commands dont throw exceptions unless ran inside a try-block(and even so u have to actually check with the docs whether they do), so ur OnError() handlers wont ever get triggered
the huge Try/Catch wouldnt allow u, for example if u wrapped 5 commands and the 2nd one threw, to proceed with the execution from the 3rd after doing something in the Catch-block
Re: What is the difference between Try/Catch and OnError()? When to use one or the other?
Thank you swagfag. I get it now!