1. Most modern advice considers exceptions to be a bad idea because you don't know which function can throw an exception, so you often end up wrapping tons of code in try-catch statements to be safe
2. There are two ways to "declare" an exception (or something that went wrong): in your return type, or in the method signature. Rust, for example, does the former (with Result<>) types, while Java does the latter (with checked exceptions)
3. These both have a large problem: What if there's an interface with a method getFoo() that returns a "T". However, your implementation wants to get the Foo over the network (or via a file). This means you'd need to return a Result<T> (or declare it on the method signature). Neither of these are possible because the interface doesn't declare it
however, this gets messy when dealing with interfaces. For example, it's common to have a Database abstracted behind a collection. You iterate over the list, and it'll actually perform a DB query
@flawr I've thought about FP, and it neatly avoids the problem by separating the two :)
@flawr and what should list.get(5) return if it errors?
if it's null, then you're basically swallowing an error, and you have this hidden edge case that the user doesn't know about.
if you throw a different (unchecked) error, then we have better error handling, but now we're back to square one: Any method can throw an error at any time
Well sometimes I'm just curious, and this is a topic I don't know a lot about, and when I'm the one asking the "stupid" questions I'm always grateful for people to discuss it with, especially if they do know a lot more about it!
there's a lot of junk I don't care about: people advertising a language, or posting a link to some video or something. My favorite posts are definitely the discussion ones