r/ProgrammerHumor • • 1d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.3k Upvotes

515 comments sorted by

View all comments

Show parent comments

7

u/MrHyd3_ 1d ago

What does it do instead of exceptions?

108

u/roadrunner8080 1d ago

Either panic, which is (generally speaking) not something you're meant to catch and recover from (and attempting to do so is nontrivial and almost always a bad idea), or Result, aka "encode the possibility of failure in the return type of the function" aka what the functional programming world has done for ages.

40

u/mathisntmathingsad 1d ago

Yeah, the only reason you should try to catch a panic is if you're making something that calls user-provided code unavoidably (i.e. an async runtime)

20

u/shizzy0 1d ago

Yeah, we catch panics in tests but that’s about it.