0

Where are exceptions handled in the MVC architecture?

Say, I am uploading a file using AJAX and an exception occurs. Where is it handled? What is the best practice for this? Should it be in the controller? So, that the view can display an alert when the exception occurs?

1

2 Answers 2

2

The Controller (as its name says) controls the execution of you application (or particular section of your application). Since it should be handling any type of I/O, it seems to be the best place to add any type of exception handling logic.

Furthermore, as you yourself realize, you can have a generic method that returns an Error-type View when an exception is thrown, or even retry the operations a couple times if needed. Neither the View, nor the Model IMO should be concerned with any exception handling logic.

1

Don't know about ajax, but exceptions should be in the controller. All listeners, try/catch and such handlers should always be in the controller, by design and by process of elimination. Even if your view throws errors, the controller should handle them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.