| LucidException.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: LucidException.java 2099 2011-03-07 17:13:00Z dmsmith $
21 */
22 package org.crosswire.common.util;
23
24 import org.crosswire.jsword.JSMsg;
25
26
27 /**
28 * A LucidException adds 2 concepts to a base Exception, that of a wrapped
29 * Exception, that of internationalized (i18n) messages.
30 *
31 * <p>
32 * The first addition is the concept of an optional wrapped Exception (actually
33 * a Throwable), which describes what caused this to happen. Any well defined
34 * interface will define the exact exceptions that the methods of that interface
35 * will throw, and not leave it to the ambiguous "throws Exception". However the
36 * interface should have no idea how it will be implemented and so the details
37 * of exactly what broke under the covers gets lost. With LucidException this
38 * detail is kept in the wrapped Exception. This functionality has been added to
39 * the base Exception class in J2SE 1.4
40 * </p>
41 *
42 * <p>
43 * The second addition is the concept of i18n messages. Normal Exceptions are
44 * created with an almost random string in the message field, LucidExceptions
45 * define this string to be a key into a resource bundle, and to help formatting
46 * this string there is an optional Object array of format options. There is a
47 * constructor that allows us to specify no i18n lookup, which is useful if this
48 * lookup may have been done already.
49 * </p>
50 *
51 * @see gnu.lgpl.License for license details.<br>
52 * The copyright to this program is held by it's authors.
53 * @author Joe Walker [joe at eireneh dot com]
54 * @see LucidRuntimeException
55 */
56 public class LucidException extends Exception {
57 /**
58 * All LucidExceptions are constructed with references to resources in an
59 * i18n properties file.
60 *
61 * @param msg
62 * The resource id to read
63 */
64 public LucidException(String msg) {
65 super(msg);
66 }
67
68 /**
69 * All LucidExceptions are constructed with references to resources in an
70 * i18n properties file.
71 *
72 * @param msg
73 * The resource id to read
74 */
75 public LucidException(String msg, Throwable cause) {
76 super(msg, cause);
77 }
78
79 /**
80 * Accessor of the full detailed version of the string
81 *
82 * @return The full unraveled i18n string
83 */
84 public String getDetailedMessage() {
85 Throwable cause = getCause();
86 if (cause == null) {
87 return getMessage();
88 }
89
90 // TRANSLATOR: When an error occurs this label precedes the details of the problem.
91 String reason = JSMsg.gettext("Reason:");
92 if (cause instanceof LucidException) {
93 LucidException lex = (LucidException) cause;
94 return getMessage() + reason + lex.getDetailedMessage();
95 }
96 return getMessage() + reason + cause.getMessage();
97 }
98
99 /**
100 * Serialization ID
101 */
102 private static final long serialVersionUID = 3257846580311963191L;
103 }
104