4 ms·
I count 185 "try" statements with only 162 "catch". I don't know much about javascript, but could someone explain what happens with the 20 that don't get caugh
by jspash 7y ago
I count 185 "try" statements with only 162 "catch".
I don't know much about javascript, but could someone explain what happens with the 20 that don't get caught? Do they bubble up and get caught by another "catch"? Or is this indicative of lots of "holes" in the code path?
- vsviridov 7y agoYou can have try/finally without the catch.
- jspash 7y agoOk, fair enough. But then does that lead to a "fatal error" of some sort? I'm curious because I find AMP page quite buggy. ie. not loading at all. Or loading, then reloading a blank page. And thought maybe these were the "dead end" code paths.
- dmitriid 7y agoIt’s caught by a higher-level catch if there is one. Try blocks without a catch are a sign of any of these: poor coding, remnants from refactoring, features started and abandoned, possibly result of some build steps combining and optimising code.
- vimslayer 7y agoTry without a catch is fairly common and IMO quite fine when it's not the current method's job to deal with an error but it is its job to clean up state or some resources. async showImage() { this.showLoadingSpinner = true try { this.imageData = await fetchImageData() } finally { this.showLoadingSpinner = false } } There might be a parent class/component/whatever that deals with errors and shows them to the user. The image component is responsible for showing the loading spinner and it shouldn't be left spinning if there's an error.