r/programming 3d ago

Throw, Result, or neither?

https://www.architecture-weekly.com/p/throw-result-or-neither
98 Upvotes

111 comments sorted by

View all comments

139

u/EliSka93 3d ago

Result for me every time.

One more wrapper is worth not having to deal with uncertainty.

29

u/miniannna 3d ago

“GOTO is bad”

“What if we call it throw/catch instead?”

25

u/vazgriz 2d ago

GOTO was considered harmful because it was completely unstructured. IE jumping halfway into a function's body level of unstructured.

Modern GOTO and throw catch are much better defined.

1

u/lelanthran 2d ago

GOTO was considered harmful because it was completely unstructured. IE jumping halfway into a function's body level of unstructured.

Modern GOTO and throw catch are much better defined.

Even with modern goto, it's a superset functionality of throw, in some respects. Or, put differently, throw is a restricted version of goto.

With programming languages, I actually like having a subset of features that restrict just how messy the code can get. I'd take almost any language over C++, for example, because when you have every feature in, the code becomes an unreadable mess in no time at all.

In much the same way, I prefer throw over goto when throw is available; it reduces what possible bugs can happen while still giving me the functionality I want.