mardi 19 juillet 2016

Having a class handling all exceptions (MVC)?

I'm writing a program following completely the MVC design pattern, currently I have lots of methods that throw exceptions and I'm handling them poorly.

I thought of adding a class in the controller called exceptionHandler, which would have methods like public void receiveRuntimeException(String message), receiveAnotherTypeOfException(...), etc.

Then giving most classes (particularly those in the view) a reference to exceptionHandler and then whenever a methods throws an exception, do something like this

try{
    methodThatWillThrowAwfulException()
}catch(AwfulException e){
    exceptionHandler.receiveAwfulException("methodThatWillThrowAwfulException threw awful exception")
}

Is this a good practice? If not, how should exceptions be handled in MVC?

Aucun commentaire:

Enregistrer un commentaire