15
What is the best place to handle an exception and send a message to the system user in a desktop application? In the controller, in the view or elsewhere?
15
What is the best place to handle an exception and send a message to the system user in a desktop application? In the controller, in the view or elsewhere?
15
In the controller.
Your model layer can produce exceptions if you are trying to perform any operation that is not allowed or if the operation to be performed fails.
The controller then captures this error and decides how the view layer will show it.
The view layer is responsible for showing the error, and perhaps capturing a user action by telling them what to do. But it’s not her responsibility to deal with the mistake.
Error handling is part of the application flow control. And flow control is the controller’s responsibility.
8
First of all do not abuse capture of exceptions. Make sure you can do something useful when you capture one and always capture the most specific exception possible.
Unfortunately Java abuses the exceptions to communicate with the various components. The language uses this mechanism for normal application flow.
That said, understand that it may be necessary to capture exceptions at any point.
During model execution exceptions may occur that need to be manipulated right there.
The same goes for visions, but it should be rare for a vision to have any exception.
Since the views should normally not have complex actions and not directly related to the presentation, these manipulations will most often invoke a controller action.
Most exceptions can be intercepted at the controller since it will be common for the model to launch them. Remembering that a probable action when an exception is captured here will be the call of a view to inform the user.
Of course this depends on the form and mainly that framework MVC is working. Some of them have their own general exception handling modes.
In general the most suitable location for capturing the application itself, and not what should be fully handled in the model or in the self-contained view is the controller who as the name says controls every application flow.
With a few details I can’t be more specific.
Browser other questions tagged java mvc exception view controller
You are not signed in. Login or sign up in order to post.