Well, as a part owner of a software company, all be it very small, I have a particular philosophy on the issue of errors, options and such.
To my mind the first thing to do is to stop thinking of errors as some special, typically unpleasant and annoying, thing that you don't really want to think about. That you want to get out of the way of your programs "happy path" that is so clean and pure and desirable.
Instead think of errors as just another thing that your program can do. Just another state it can get into. Clear your mind of any difference between that nice clean concept of your algorithm or code execution path and some other path that you now think of as "error".
Why? Because errors happen. They are a normal part of the life of your code. As surely as death and taxes are for us. You have to deal with them as surely as any other step in your program. You have to cater for "errors" somehow just like any other decisions made in your program.
What this means is that how you respond to what you think is an error situation entirely depends on what you want or need to do when it happens. Maybe not being able to open a file is fatal and the program cannot continue, for example when a config is missing. Or perhaps the user just mistyped a file name and you have to notify the user of that and see what they want to do next.
What I'm getting at is that often we see that people design some code for the functionality they want but they forget to anticipate and design for all the ways it might not go as they expect. The they have a quandary, how do I handle that?
As an example I spend a couple of months building some code that relied on communicating with another device. My plan was that if the communication failed for any reason it may as well just quit with an error message as soon as possible. It's OK, I thought, systemd will start it up again. Turned out though that what I really needed to do was a whole bunch of other things to shut down nicely else the whole system collapsed. At that point it's not a question of should I use unwrap
or match
or ?
, no it's major overhaul of how the whole thing worked.
Sorry, I'm rambling a bit....
But to close, this is why I don't much like the idea of exceptions and to some extent ?
. Maybe there is 10 ways my function might not do what I expect. Likely most of them are not really "exceptional". Worse cleaning up my "happy path" by simply throwing an exception or using ?
just means I have hyper spaced my problems to some other unknown part of the code with the hope they will deal with it.