News for hackers. Stuff that matters.
Re:JEP draft: Exception handling in switch by codedokode on Friday April 19, 2024 @01:51PM (#40089913)
This means you will have to write an if after every method call which is annoying and makes code less readable (source: had to write lots of ifs several days ago while writing a C library. My code consists mostly of ifs with error handling, because almost every function - even encoding conversion - can fail. I think that if companies hired low-paid trainees just for the purpose of writing ifs they could save a lot).
Re:JEP draft: Exception handling in switch by eyelidlessness on Friday April 19, 2024 @02:03PM (#40090061)
Presumably one of these applies:

* You have a sequence of steps, and only care about a general error condition occurring somewhere in range of those; in which case, it makes sense to abstract something to treat those steps as a unit and collect any error from that

* You don’t need to handle any errors directly, and wish to propagate them to the caller; in which case, doing so explicitly is better than not

* You should handle the errors; in which case, complaining about that doesn’t make much difference

Re:JEP draft: Exception handling in switch by bedobi on Friday April 19, 2024 @01:56PM (#40089981)
I don't mean to be uncharitable but no, that's not how it works. You pass the Either<Error, Foo> or Maybe/Option<Foo> around, usually to the edge of the system where you map, flatMap or fold it into something.
Re:JEP draft: Exception handling in switch by codedokode on Saturday April 20, 2024 @11:25AM (#40098066)
But this is ugly, for example, if I have a square root function, I don't want it to accept Error.
Re:JEP draft: Exception handling in switch by bedobi on Monday April 22, 2024 @04:33PM (#40119926)
No function should accept error
Re:JEP draft: Exception handling in switch by mrkeen on Friday April 19, 2024 @01:56PM (#40089970)
If it's repetition, you can abstract it away.
Re:JEP draft: Exception handling in switch by mightyham on Friday April 19, 2024 @02:14PM (#40090206)
There are very few cases where you can abstract away error handling because it's extremely context dependent.