4 ms·
"What are exceptions used for" is similar to tabs versus spaces. Many languages just "leave that part to the user". Which I think is wrong. Or at least, ineffic
by otikik 3y ago
"What are exceptions used for" is similar to tabs versus spaces. Many languages just "leave that part to the user". Which I think is wrong. Or at least, inefficient. Different people will make different assumptions and then we will have a clash of opinions.
- davedx 3y agoYeah, the amount of bike shedding and yak shaving I've been pulled into over "how exceptions should be used" is pretty dismal. The worst thing is, I've still not even 100% decided myself. I think that does say something about the design of exceptions.
- shrimp_emoji 3y agoThey should not be used.
- davedx 3y agoWell I definitely disagree on that. I fall more on the side of “use them for regular errors too” because IMO anything that reduces boilerplate is a good thing. But I also don’t like “magic” so it’s still a bit in tension in my head
- tomp 3y agoWhat happens when 1/0 though? Or socket disconnects?
- norir 3y agoIt's all about definitions. For me, the difference between exceptions and panics is the former is recoverable. You can write a language with panic but no catch to ensure that panic crashes the whole program every time it is invoked. let x = if foo then bar else panic("unhandled case !foo") end Panic allows you to enumerate cases without implementing them, which can be very helpful in development. As I build out functionality, my code crashes exactly where I need to implement the new case, but I can implement the initial happy path all the way to completion. try/catch on the other hand, I'm not a fan.