Re:A better way to handle errors in JavaScript
by optimistprime on Tuesday October 31, 2023 @01:54AM
(#38080799)
This is interesting. Does it have any performance impact?
Re:A better way to handle errors in JavaScript
by musicq on Tuesday October 31, 2023 @06:20AM
(#38082578)
Don't think would affect performance. The core function `wrap` is just try catch under the hood.
https://github.com/musicq/unwrapit/blob/d5c437a235ad1f5ad042...
Re:A better way to handle errors in JavaScript
by optimistprime on Sunday November 05, 2023 @05:06PM
(#38156124)
iirc, try catch does have performance impact in js.
Re:A better way to handle errors in JavaScript
by slawr1805 on Tuesday October 31, 2023 @02:03AM
(#38080855)
This is awesome! I dig this when using Rust and am pumped to try and sneak this in at work where we have a large TS codebase.
Re:A better way to handle errors in JavaScript
by jwhiles on Tuesday October 31, 2023 @02:51AM
(#38081098)
This is a nice project, but it kind of feels like the result of someone who's just learnt about Rust/Haskell and wants to port what they know to JavaScript.
There's a lot of more established and battle tested libraries with the same functionality - I've recently been using Purify and finding it to be absolutely fine :)
their version of the same feature is here: https://gigobyte.github.io/purify/adts/Maybe
Re:A better way to handle errors in JavaScript
by grose on Tuesday October 31, 2023 @03:36AM
(#38081339)
Whoa, these docs are really nice. Love how it includes the functional Haskellish signature, TS signature, and useful examples for each. Props to the authors.
Re:A better way to handle errors in JavaScript
by fearface on Tuesday October 31, 2023 @02:07AM
(#38080879)
I think the idea of try/catch is to let the error bubble up to the place where it can be handled. It usually results into having error handling in a few central places. Your example in github is IMO not how to make best use of try/catch.
Here’s lots of typical exception handling patterns: http://wiki.c2.com/?ExceptionPatterns
Persobally I prefer exceptions over boilerplate “if’s”, but good to know that there’s a wrapper for the people who don’t.
Still think this might be a proper way to deal with errors in JS/TS