C
C#3y ago
KidKai25

❔ ✅ What is the bestright thing to do when an Exception occurs say, in my MVC application?

Catch the exception and log Catch the exception and do nothing. Throw the exception. Do nothing. It depends on me as a dev
4 Replies
Timtier
Timtier3y ago
Catch the exception and do something to inform the user (if appropiate) You could start with a generic message like: "Failed to [do something], please try again"
KidKai25
KidKai25OP3y ago
When is it appropriate to use throw then?
Timtier
Timtier3y ago
At the place where the exception actually occurs So lets say you have an api which has multiple layers; The controller which calls a Handler class, which itself calls a class that handles database stuff If a user calls the controller to save something, but that fails in the database class, it will throw an exception Which should be caught by either the handler that it was called for or the controller (other options are available too but I will exclude them for simplicity) Then in that catch clause of the controller you can return to the user that something failed.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity. Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?