aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes MVC, Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "MVC, Exception Handling" Watch "MVC, Exception Handling" New topic
Author

MVC, Exception Handling

Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi,
The controller in sample project in the Max book wraps all exceptions in the GUIException. The View (Main Window) handels then all exceptions.


I have threads in my GUI client. It means that my Controller doesn't rethrow exception
directly, rather then change appropriate model (RequestModel), which send events to the View. If I just wrap original exception to the GUIException (which will be passed to the client with RequestModel to the view) without changing its message, the view will not be able to detect where the problem occured (e.g. while searching or booking).
Thus, I manage all exception not in the view, but in Controller and I pass only an appro message to the client. This is part of the code in the controller, serving find request:

In the booking request I my Controller handles also such exceptions like RecordNotFoundException or RecordChangedException and so on.
As you see, the difference betweem my client and Max's one is that he deliveres all exceptions (wrapped in the GUIControllerException) to the view and then handles them and
I do it already in the Controller and deliver only the message to the view.
I don't have any experience with client programming, expecially MVC design.
Could you please comment if it Ok to delegate exception handling to the controler instead of view the way I have done it?
Tx,
Vlad
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Vlad,
These are my comments, I may be wrong:
I think that the question that you are raising are a matter of personal taste. MVC architecture doen't favor Max's style of exception handling over yours. The way I see the MVC pattern being applied to our assignment is more towards the presentation side. It seems to me that you are favoring handling of exception more within the Model piece of the presenation layer using an "event" dispatcher type pattern than Max who is handling it further up but still within the controller part of the MVC architecture. ApplicationRunner class is merely a view (dialog) presentation mechanism in his design.
Again, I may have misunderstood your question. My experience in MVC comes from Struts framework which you must be familiar with.
Regards.
Bharat.


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Bharat,
It seems to me that you are favoring handling of exception more within the Model piece of the presenation layer using an "event" dispatcher

Honestly saying, I am not favoring it, I just don't have any other idea than that to deliver an exception to the view (Ok, probably an observer pattern also) without breaking MVC pattern, since I use threads and just cannot do the same as Max did...
Is there any other simpler and eleganter way to do it?
Vlad
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Yes. Don't use threads in your presentation layer design. IMO.
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Bharat,
Well I have thown today all threads away
I have reduced my application by 3 classes (RequestModel, RequestEvent, RequestListener). I have now the the design like Max.
I beleive having no threads makes the client ugly, but design simpler...
Do you think it Ok in the view to use "instead of" to idetify a real exception which caused GUIControllerException, like Max did?
(It is not a critic, it is just a question).
Vlad
[ August 20, 2003: Message edited by: Vlad Rabkin ]
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Valdimir,
You wrote:

Well I have thown today all threads away
I have reduced my application by 3 classes (RequestModel, RequestEvent, RequestListener). I have now the the design like Max.
I beleive having no threads makes the client ugly, but design simpler...

I am glad that you decided to simplify your design. As far as this assignment is concerned, this is enough.

Do you think it Ok in the view to use "instead of" to idetify a real exception which caused GUIControllerException, like Max did?
(It is not a critic, it is just a question).

I am afraid that I don't understand what do you mean by "instead of" in the above quote. If you will elaborate on it may be I will be in a position to comment on it? Do you mean to say that wrapping an unrelated exception in a GUIControllerException is a problem? That is the only way that I know (learned it from Max's book and the JDK 1.41 Tutorial by Greg Travis) of chaining exceptions. Moreover, as long as you can get to the root cause for the underlying exception, it is OK IMO. If you will point to specific page numbers in his book, I can get a better context for your question.
Regards.
Bharat
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Bharat,
Tx for your help!
Upsss, I ment "instance of" ... :roll:
That is:

Tx,
Vlad
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Originally posted by Vlad Rabkin:
Hi,
The controller in sample project in the Max book wraps all exceptions in the GUIException. The View (Main Window) handels then all exceptions.


I have threads in my GUI client. It means that my Controller doesn't rethrow exception
directly, rather then change appropriate model (RequestModel), which send events to the View. If I just wrap original exception to the GUIException (which will be passed to the client with RequestModel to the view) without changing its message, the view will not be able to detect where the problem occured (e.g. while searching or booking).

Hi Vlad,
I'm confused. Why not just throw a GUISearchException, GUIBookingException, etc?. That was the whole point of the design.
M


Java Regular Expressions
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Max,
Why not just throw a GUISearchException, GUIBookingException, etc

It is not a problem! Right. It was so simple. Every time I get your answers I think I have to take a vacation
There is one more problem: Since I have threads, I can't throw an Exception anyway directly to the view, as you did... So, I beleive I need to use anyway my self-defined events to deliver it to the client. Right?
Max, let me use the chance that you are on-line and ask you some relevant questions:
1) You used instanceof in the view do define what the real exception occured (see a sample in my previous message). I followed your idea.
Do you think it is Ok to use it here? (I have always tried to avoid instanceof in my programmes, since I thought it is not a very good thing in OO)
2) I beleive having a multithreaded client to my opinion is almost a obligatory thing. It brings, of course, complexity, such as createing own Event, Listener, Model classes or Observers to pass results of operation cleanly by not breaching MVC concept (Exceptions are good example), or creating anonymious classes for invokeLater and so on.
As I said I just throught all threads from my client away and saved pretty much code.
It looks like nobody was penaltied for not using single-threaded client.
Am I on the right track by moving my client to the single-threaded model?
Tx,
Vlad
[ August 20, 2003: Message edited by: Vlad Rabkin ]
[ August 21, 2003: Message edited by: Vlad Rabkin ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11422
    
  85

Hi Vlad,
Thought I'd continue on the trend of answering questions addressed to other people that seems prevelant in this post
1) You used instanceof in the view do define what the real exception occured (see a sample in my previous message). I followed your idea.
Do you think it is Ok to use it here? (I have always tried to avoid instanceof in my programmes, since I thought it is not a very good thing in OO)

Personally I dont think there is any problem with this, even in OO terms. What we are doing here is potentially being able to give a user a more relevant error message.
So when we get the GuiBookingException, we can use instanceOf to try and give the user a more detailed error message (for example: "already booked" or "record not found"). But if the exception is not an instanceOf a known subclass of GuiBookingException, we can still provide the user with a (hopefully) usefull message telling them that there was a problem.
And if the lower level implemenation details change later, such that the particular subclassed exception is not thrown, it will not affect our program - our program will still display the default error message to the user.
I beleive having a multithreaded client to my opinion is almost a obligatory thing. [...] It looks like nobody was penaltied for not using single-threaded client.
Am I on the right track by moving my client to the single-threaded model?

In one respect I am sorry to see you move away from the multi threaded client. For a real system (especially one that might work over the internet rather than an internet) you would almost definately want a multi threaded client just so it is still responsive. And as we have commented before, this assignment is a great opertunity to learn how to do things you are not familiar with.
But on the other hand, it is definately a good idea to keep things simple in this assignment. So if the multi threads were causing your code to become more confusing, then perhaps it is good that you removed it.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Andrew,
Your statements have convinced me.
May I ask one more question: do you live in Europe or in USA?
I thought you are from Europe, because you messages were coming usually already starting at the morning time in Europe, but sometimes you write message at late evening in USA!?
Looks, like you are 25 hours per day on-line !
Of course ,I don't mind it
Thanx a lot for your help!
Vlad.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11422
    
  85

Hi Vlad,
I thought you saw those people accusing me of being an insomniac in Sydney, Australia Last year I was living in London, and for the two years prior to that I was in Holland.
I know it seems like I am on 24/7, but in reality I am on for several half hour sessions throughout the day, depending on when I feel like a break from whatever I am studying.
Regards, Andrew
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Andrew,
You still didn's where you live now ...
I thought you saw those people accusing me of being an insomniac in Sydney, Australia

Nope, but now I join to the point of these people
Andrew, I am developing now two small classes providing locking , trying to demonstrate my understanding of your locking mechanism and Jim's one.
I want to make sure I really understood your ideas and multithreading.
I will ask you to review these classes (they will be small).
May I publish them in the new topic or I would better send the code as a private message, since no design implementation are probably allowed to be published?

Regards,
Vlad
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11422
    
  85

Hi Vlad,
You still didn's where you live now ...

:roll: You can find my bio here, along with all the other bartenders. I apologise in advance if any of the bartender's photos (especially mine) scare you
I am developing now two small classes providing locking ... May I publish them in the new topic

Hmmmm - do you recall any of my code snippets designed to show a concept? Or Mark's fantastic post showing MVC? Posting code showing concepts is allowed.
So if the classes you are developing are proof of concept classes that are not specific to the assignment, then you should be able to post them in a new thread here. This would be more beneficial to everyone here. Please try and keep the concept generic if you do that.
Regards, Andrew
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Andrew,
I apologise in advance if any of the bartender's photos (especially mine) scare you

Well, it wasn't so scaring Just a joke. It is hard as a man to judge it, but you look great.
Please try and keep the concept generic ...

That is what I am trying to do and that is what the hardest task is.
Ok. Thanx.
Vlad
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC, Exception Handling