01: package simpleorm.core;
02:
03: /** This Exception thrown by user written code to indicate user data
04: entry errors, especially in the business rule methods. The idea is
05: that the calling method can trap them and present neat messages to the
06: user. Do not use this exception for mysterious internal errors, only
07: for well defined user errors that do not require a stack trace.<p>
08:
09: ### Should add hooks for localizing messages etc.
10: */
11:
12: public class SValidationException extends RuntimeException {
13: SRecordInstance instance;
14:
15: /** message is formatted with MessageFormat and param. */
16: public SValidationException(String message, Object param,
17: SRecordInstance inst) {
18: super (prettyMessage(message, param));
19: instance = inst;
20: }
21:
22: public SValidationException(String message, Object param) {
23: this (message, param, null);
24: }
25:
26: public SValidationException(String message) {
27: this (message, null);
28: }
29:
30: static String prettyMessage(String message, Object param) {
31: Object[] params = null;
32: if (param instanceof Object[])
33: params = (Object[]) param;
34: else if (param == null)
35: params = new Object[0];
36: else
37: params = new Object[] { param };
38: return java.text.MessageFormat.format(message, params);
39: }
40:
41: public SRecordInstance getRecordInstance() {
42: return instance;
43: }
44: }
|