in tpb's example, the function is the library, the user writes the error for you. But it is a overly simple example.
You could make the user load the file for you, and pass an already valid ifstream as a file for the init function. Very good if there is only 1 other possible error, which is from curruption of data.
If you want various errors and you want to avoid exceptions, I could also see simple error callback system. The client just defines a function with a string as a parameter, or if no callback is made you can just call stdout all you want, and now the simple bool system works again!
Otherwise there is nothing wrong with exceptions, just call exceptions in any way you want, it all leads to the same result.
LIBNAME: Something Happened! |
.
I guess you could allow users to overwrite specific exceptions in catch chains, but its quite rare for people to actually care about that, other than std's code since sometimes its not something a non-programmer should ever read like casting error or out of bounds, and for a programmer, WHERE did it happen? line? file?
So you have to be careful to not leak any std related exceptions out of your library.