More than 25 years experienced software enthusiast. Loves a bunch of programming languages and technologies. Writes about tech React, Javascript, Rust...
Interesting, I didn't think of trying it while writing the article but I just tried this:
try{throwundefined}catch(error){console.log((errorasError).message)}finally{console.log('this will log');}console.log('code here is unreachable because "catch" threw a TypeError')
And yes, finally will run but your application will still be unstable. I will add an edit shortly in the article to clarify that point. Thanks for the feedback
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Of course, me too;) But in some cases it's critical.
I mean the following use cases...
This is a good theoretical example:
finally works even here...
... and BTW here:
'finally' is a unique and the safest way to close/destructurise the "try-catch flow".
Let me focus on the practical part. Say, we work with the DB...
This is an anti-pattern:
This is a pattern:
I hope it helps you to continue with this vital topic ;)
Interesting, I didn't think of trying it while writing the article but I just tried this:
And yes,
finallywill run but your application will still be unstable. I will add an edit shortly in the article to clarify that point. Thanks for the feedback