Open Hadaward opened 5 months ago
That seems like a good alternative syntax to consider once pattern matching’s shape is solidified.
I think it implicitly introduces Typization to JS (or at least it looks like it, which adds ambiguity), I would also wanted it but not this way. The more JS-style would be something like this (IMHO)
try {
// some error producing code
} catch (error; error instaceof TypeError) {
console.error(`We got the known error: ${error}`);
} catch (error; error instaceof SyntaxError) {
console.error(`We got another known error: ${error}`);
} finally {
// handle shutdown
}
That would also allow matching any boolean value, which is more flexible.
what is "typization"?
I know it might be a little confusing at first but I don't think the original syntax is bad, we could just do something like try..match to specify that "error" instantiates a certain class.
The syntax for match is questionable and debatable, but I prefer to keep the part that we don't have an implicit variable to get the error data, an explicitly named variable is much better.