Suppose a function is called, in which 2 more other functions are called, in which several other functions are called. Where do I get an exception message? To wrap each function in try-catch and to locally output an error? Or to wrap each function in try-catch , and in catch to throw ( throw ) the exception further, to the very first function? Or is there no big difference?

    1 answer 1

    Where you are no longer able to handle an exception, other than to display a message.

    If the function fails to handle the exception, it is better to pass it up to the calling function: perhaps it will be able to deal with it better. Well, in main , if nothing else remains, then ...

    For example, the function should open a file that does not exist, and an exception is generated. Display a message? And if this function is just a part of the algorithm that works with user input, and the user simply made a mistake and can enter a new file name, if he is offered this?

    In short, there are no specific advice - do it and not otherwise. The usual rule is that someone who knows how to handle an exception intercepts.

    "I think so" (c) Pooh