3 ms·
Using exceptions would be a lot easier however if typescript picked up the throws and would warn about missing catch blocks, just as every other language with e
by 9dev 4y ago
Using exceptions would be a lot easier however if typescript picked up the throws and would warn about missing catch blocks, just as every other language with exceptions seems to get right…
- hot_gril 4y agoIf your function doesn't handle an exception, it throws it. If TS required you to say `throws` every time like in Java, that'd be repetitive like explicitly returning `| Exception`. Maybe it could detect if you're not catching in the outer event loop. Idk though, I just use vanilla JS and don't find these safeguards necessary. Worst case, if I fail to handle something, my NodeJS express server will handle it by sending back a 500.
- 9dev 4y agoYeah, but I would want to know which library function could possibly throw an error and not be caught off guard by that after deploying to prod :-/
- hot_gril 4y agoIt's almost accurate to assume that everything can throw an error in high-level code like this, especially in something complex enough to warrant a lib. The thing is, in a webserver, those are all unexpected errors and thus 500. There are only a few known ways the client can use it wrong, and I give 400 for those.