Results 1 to 6 of 6
  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Question 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 :
    Java 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

  2. #2
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: ErrorHandling on MVC

    You could instantiate the Controller first and have it instantiate the Model and the View.

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default 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?
    Last edited by Sierra; 01-11-2013 at 09:34 AM.
    I like likes!

  4. #4
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default 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 :

    Java Code:
    Controller c = new Controller();
    c.setModel = new Model();
    c.setView = new View();
    Kind regards

  5. #5
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: ErrorHandling on MVC

    I was thinking something more like this, but I'm only now learning MVC myself.

    Java Code:
    class Model {
    }
    
    class View {
    }
    
    public class Controller {
    	
    	private Model model;
    	private View view;
    	
    	public Controller() {
    		this.model = new Model();
    		this.view = new View();
    	}
    
    }

  6. #6
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default Re: ErrorHandling on MVC

    Hi,

    But in this solution the model is in the controller and cannot be changed.

    Kind regards

Similar Threads

  1. ErrorHandling in Java
    By SindhuPal in forum New To Java
    Replies: 3
    Last Post: 10-16-2012, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •