
klondike schrieb:
Now comes the time when I have to show you that not every exception could be handled, IE a file not found exception when looking for the config file can be fatal and force the program to stop. But what if this is on a library? How do you suggest that the programmer knows that the File Not Found exception is due to the lack of that config file, specially when the code is badly (or not) documented.
A library function that reads a config file may declare to be able to throw the exception "File not found", or it may introduce a new exception "Could not read Config file" with an extra field for the reason, why the file could not be read. This way you can construct a call stack that helps the user (and not the programmer). Then the message reported to the user might be: Program could not be started, because Config file could not be read because Config file does not exist in dir0, dir1, dir2 but the exception handler may also decide to use a default configuration instead or ask the user, how to proceed. Anyway, such a call stack for the user requires different information than a call stack for programmer for debugging.