I have been debating this matter for ages now, reading up on it, but I can't come to a decision.
I'm writing a library (for personal use) for web applications, which should be as efficient as possible. Consider a read() function as an example. It will read something from the database and it's contents are passed to a template.
Following things could go wrong in the read() function: a database error, the resource may not exist or may be empty, etc.
Now, I can't decide whether functions like read() should throw exceptions, or return error codes. I have read this, among may others: http://www.boost.org/community/error_handling.html
Which asks "do you need stack unwinding"? No, I probably don't. But when a resource is not available, the information cannot be shown to the end user either, so it would be nice to "force" the caller to handle that accordingly. Another benefit of exceptions is that they can be thrown one or two levels deeper and handled in one common place. The "depth" from throw to catch should never be more than 2 or 3 levels I think, but might that be enough to cause a performance hit?
So I'm basically dealing with "status codes", not exceptional situations, so it might be dubbed an abuse of the exception capabilities?
As you may be able to tell, I'm completely lost - both sides have valid arguments and I can't decide - so I'd like to get your opinions on this.
Thanks very much in advance.
All the best,