-
ErrorHandling on MVC
Hi,
I have a program in MVC.
The Model and the view send exception (FileNotFound, IO...) to the Controller, witch threads the errors.
But when i start the Model, he has to read from a config file.
Since the controller is not started yet, i cannot pass the exception in case of an error to the Controller.
Is this good practice :
Code:
public static void main(String[] args) {
Model m = new Model();
View v = new View();
Controller c = new Controller(m, v);
m.readConfig();
}
What is the best way of threading exceptions from model and view in a MVC ?
Kind regards
Dipke
-
Re: ErrorHandling on MVC
You could instantiate the Controller first and have it instantiate the Model and the View.
-
Re: ErrorHandling on MVC
I do not understand your problem at all... who prevents you from handling the exception on the level of your method? Or wait for the controller to be initialized before loading the configuration?
-
Re: ErrorHandling on MVC
Hi,
The Exception is threated on the level of the method, but an errormessage is displayed on the screen using a view.
And that is initialized when the controller starts. So the controller must be started before the message can be displayed.
@kaydell2 : is this what you mean :
Code:
Controller c = new Controller();
c.setModel = new Model();
c.setView = new View();
Kind regards
-
Re: ErrorHandling on MVC
I was thinking something more like this, but I'm only now learning MVC myself.
Code:
class Model {
}
class View {
}
public class Controller {
private Model model;
private View view;
public Controller() {
this.model = new Model();
this.view = new View();
}
}
-
Re: ErrorHandling on MVC
Hi,
But in this solution the model is in the controller and cannot be changed.
Kind regards