|
1 package hirondelle.web4j.model; |
|
2 |
|
3 /** |
|
4 Thrown when a Model Object (MO) cannot be constructed because of invalid |
|
5 constructor arguments. |
|
6 |
|
7 <P>Arguments to a MO constructor have two sources: the end user and the |
|
8 the database. In both cases, errors in the values of these arguments |
|
9 are outside the immediate control of the application. Hence, MO constructors |
|
10 should throw a checked exception - (<tt>ModelCtorException</tt>). |
|
11 |
|
12 <P>Using a checked exception has the advantage that |
|
13 it cannot be ignored by the caller. |
|
14 |
|
15 Example use case:<br> |
|
16 <PRE> |
|
17 //a Model Object constructor |
|
18 Blah(String aText, int aID) throws ModelCtorException { |
|
19 //check validity of all params. |
|
20 //if one or more params is invalid, throw a ModelCtorException. |
|
21 //for each invalid param, add a corresponding error message to |
|
22 //ModelCtorException. |
|
23 } |
|
24 |
|
25 //call the Model Object constructor |
|
26 try { |
|
27 Blah blah = new Blah(text, id); |
|
28 } |
|
29 catch(ModelCtorException ex){ |
|
30 //place the exception in scope, for subsequent |
|
31 //display to the user in a JSP |
|
32 } |
|
33 </PRE> |
|
34 |
|
35 <P>In the case of an error, the problem arises of how to redisplay the original, |
|
36 erroneous user input. The {@link hirondelle.web4j.ui.tag.Populate} tag |
|
37 accomplishes this in an elegant manner, simply by recycling the original |
|
38 request parameters. |
|
39 */ |
|
40 public final class ModelCtorException extends AppException { |
|
41 //empty |
|
42 } |
|
43 |