3 ms·
In this case, if the error object is undefined/null, then error.messsage throws a TypeError, and the spinner is not hidden. In general the finally { ... } bloc
by tantalor 9y ago
In this case, if the error object is undefined/null, then error.messsage throws a TypeError, and the spinner is not hidden.
In general the finally { ... } block is useful because it is guaranteed to execute after the try/catch (if the program has not exited), where as the next line after the try/catch is not, e.g., the try/catch returns, or the catch block throws.
- hughes 9y agoIf that's what the example is showing, then it's just obscuring two unrelated try/catch blocks. One for the outcome of the request, and one for the uncertainty of the element reference.
- l1ambda 9y agoExample: (()=>{try {return 42} finally {console.log('you will see this')}})() The fn body returns 3, but also the "finally" executes first and you get the console.log. Same with: (()=>{try {throw 42} finally {console.log('you will see this')}})()