001: /* SystemException.java
002:
003: {{IS_NOTE
004:
005: Purpose: Thrown if a caught exception is not in the exception list.
006: Description:
007: History:
008: 2001/5/15, Tom M. Yeh: Created.
009:
010: }}IS_NOTE
011:
012: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.lang;
020:
021: import org.zkoss.mesg.Messageable;
022:
023: /**
024: * Indicates a system exception.
025: *
026: * @author tomyeh
027: */
028: public class SystemException extends RuntimeException implements
029: Messageable {
030: /** Utilities.
031: *
032: * <p>The reason to use a class to hold static utilities is we can
033: * override the method's return type later.
034: */
035: public static class Aide {
036: /** Converts an exception to SystemException or OperationException
037: * depending on whether t implements Expetable.
038: * @see Exceptions#wrap
039: */
040: public static SystemException wrap(Throwable t) {
041: t = Exceptions.unwrap(t);
042: if (t instanceof Warning)
043: return (WarningException) Exceptions.wrap(t,
044: WarningException.class);
045: if (t instanceof Expectable)
046: return (OperationException) Exceptions.wrap(t,
047: OperationException.class);
048: return (SystemException) Exceptions.wrap(t,
049: SystemException.class);
050: }
051:
052: /** Converts an exception to SystemException or OperationException
053: * depending on whether t implements Expetable.
054: * @see Exceptions#wrap
055: */
056: public static SystemException wrap(Throwable t, String msg) {
057: t = Exceptions.unwrap(t);
058: if (t instanceof Warning)
059: return (WarningException) Exceptions.wrap(t,
060: WarningException.class, msg);
061: if (t instanceof Expectable)
062: return (OperationException) Exceptions.wrap(t,
063: OperationException.class, msg);
064: return (SystemException) Exceptions.wrap(t,
065: SystemException.class, msg);
066: }
067:
068: /** Converts an exception to SystemException or OperationException
069: * depending on whether t implements Expetable.
070: * @see Exceptions#wrap
071: */
072: public static SystemException wrap(Throwable t, int code,
073: Object[] fmtArgs) {
074: t = Exceptions.unwrap(t);
075: if (t instanceof Warning)
076: return (WarningException) Exceptions.wrap(t,
077: WarningException.class, code, fmtArgs);
078: if (t instanceof Expectable)
079: return (OperationException) Exceptions.wrap(t,
080: OperationException.class, code, fmtArgs);
081: return (SystemException) Exceptions.wrap(t,
082: SystemException.class, code, fmtArgs);
083: }
084:
085: /** Converts an exception to SystemException or OperationException
086: * depending on whether t implements Expetable.
087: * @see Exceptions#wrap
088: */
089: public static SystemException wrap(Throwable t, int code,
090: Object fmtArg) {
091: t = Exceptions.unwrap(t);
092: if (t instanceof Warning)
093: return (WarningException) Exceptions.wrap(t,
094: WarningException.class, code, fmtArg);
095: if (t instanceof Expectable)
096: return (OperationException) Exceptions.wrap(t,
097: OperationException.class, code, fmtArg);
098: return (SystemException) Exceptions.wrap(t,
099: SystemException.class, code, fmtArg);
100: }
101:
102: /** Converts an exception to SystemException or OperationException
103: * depending on whether t implements Expetable.
104: * @see Exceptions#wrap
105: */
106: public static SystemException wrap(Throwable t, int code) {
107: t = Exceptions.unwrap(t);
108: if (t instanceof Warning)
109: return (WarningException) Exceptions.wrap(t,
110: WarningException.class, code);
111: if (t instanceof Expectable)
112: return (OperationException) Exceptions.wrap(t,
113: OperationException.class, code);
114: return (SystemException) Exceptions.wrap(t,
115: SystemException.class, code);
116: }
117: }
118:
119: protected int _code = NULL_CODE;
120:
121: /**
122: * Constructs a SystemException by specifying message directly.
123: */
124: public SystemException(String msg, Throwable cause) {
125: super (msg, cause);
126: }
127:
128: public SystemException(String msg) {
129: super (msg);
130: }
131:
132: public SystemException(Throwable cause) {
133: super (cause);
134: }
135:
136: public SystemException() {
137: }
138:
139: /**
140: * Constructs an SystemException by use of an error code.
141: * The error code must be defined in
142: * one of properties files, e.g., msgsys.properties.
143: *
144: * @param code the error code
145: * @param fmtArgs the format arguments
146: * @param cause the chained throwable object
147: */
148: public SystemException(int code, Object[] fmtArgs, Throwable cause) {
149: super (Exceptions.getMessage(code, fmtArgs), cause);
150: _code = code;
151: }
152:
153: public SystemException(int code, Object fmtArg, Throwable cause) {
154: super (Exceptions.getMessage(code, fmtArg), cause);
155: _code = code;
156: }
157:
158: public SystemException(int code, Object[] fmtArgs) {
159: super (Exceptions.getMessage(code, fmtArgs));
160: _code = code;
161: }
162:
163: public SystemException(int code, Object fmtArg) {
164: super (Exceptions.getMessage(code, fmtArg));
165: _code = code;
166: }
167:
168: public SystemException(int code, Throwable cause) {
169: super (Exceptions.getMessage(code), cause);
170: _code = code;
171: }
172:
173: public SystemException(int code) {
174: super (Exceptions.getMessage(code));
175: _code = code;
176: }
177:
178: //-- Messageable --//
179: public final int getCode() {
180: return _code;
181: }
182: }
|