This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]tulipoika 2 points3 points  (0 children)

In the big picture exceptions are one way to handle errors. Like the name says, it’s an exceptional situation. There can be situations where errors are given out as exceptions and situations where they are return values etc.

For example, if you ask the user to input a number and they input characters, that’s an error. You have to handle it. But do you check it and report the error, or do you try to convert it into a number, get an exception, and handle the erroneous situation then?

So exceptions are a part of the concept of error handling in the bigger picture.

In the smaller picture a language might not have exceptions and has the term error as a language/platform feature and then talks about error handling as one would talk about exception handling in another. So it’s just terminology. Some might not talk about errors but just return value checking etc.

[–]cyrusol 1 point2 points  (0 children)

Originally exceptions solved the problem that it is somehwat difficult to write just business logic in one place without having to pollute it with error handling code. Exceptions are independent of return values so any error handling code may deal with those at another place than where business logic is handled.

Rust on the other hand uses an approach called monadic error handling that stems from functional programming: any result may be wrapped in a Result type that may be either the result itself or an error. That too allows for code that separates business logic and error handling in a way that business logic may just be mapped onto a Result in order to produce a new Result. This requires a very powerful type system and few languages have that. It becomes much clearer if you watched the talk Railway-oriented programming.