3 ms·
The problem is sometimes you need to be able to report an exception elsewhere than the global log file , for example fold the exception into a user response. Fo
by Aqueous 13y ago
The problem is sometimes you need to be able to report an exception elsewhere than the global log file , for example fold the exception into a user response. For a web application, for instance, using ANORM/Scala/Play, you might have a unique key constraint that throws an exception when it's violated. I need to be able to use that to emit a JSON response to the user telling them there is already a file with that name, extension combination etc. So I have to catch the exception in my controller in order to properly report that to the user.
The author is right that your code needs to properly react to exceptions and not swallo them. . A global exception handler lets you report to all exceptions, but in order to give proper feedback to the user you definitely have to catch exceptions elsewhere in the code.