On 10/12/20 2:11 AM, Dominikus Dittes Scherkl wrote:

> - Throw exceptions only if you have a plan what to do with them if you
> catch them.

My thinking is different: Throw exceptions if you can't accomplish a task. My code is filled with enforce() and assert() checks, which do throw exceptions.

> - If you have no plan, better throw error, just to get an idea where and
> why the program crashed (and don't try to catch them)

In most cases, catching Exception (not Error) to print exc.msg is fine and is the correct thing to do. (Errors are not caught, the stack trace is printed, and that's helpful.)

Occasionally, exc.msg of an Exception doesn't give enough information. So, printing exc (not exc.msg) temporarily to look at the stack trace is helpful.

Ali

Reply via email to