01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package javacard.framework;
28:
29: /**
30: * The <code>CardException</code> class
31: * defines a field <code>reason </code>and two accessor methods <code>
32: * getReason()</code> and <code>setReason()</code>. The <code>reason</code>
33: * field encapsulates an exception cause identifier in Java Card.
34: * All Java Card checked exception classes should extend
35: * <code>CardException</code>.
36: */
37:
38: public class CardException extends Exception {
39: /** Reason code for the detected error. */
40: private short reason;
41:
42: /**
43: * Constructs a <code>CardException</code> instance with the
44: * specified reason.
45: * @param reason the reason for the exception
46: */
47: public CardException(short reason) {
48: setReason(reason);
49: }
50:
51: /**
52: * Gets the reason code.
53: * @return the reason for the exception
54: * @see #setReason
55: */
56: public short getReason() {
57: return reason;
58: }
59:
60: /**
61: * Sets the reason code.
62: * @param reason the reason for the exception
63: * @see #getReason
64: */
65: public void setReason(short reason) {
66: this .reason = reason;
67: }
68:
69: /**
70: * Throws an instance of <code>CardException</code> class with the
71: * specified reason.
72: * @param reason the reason for the exception
73: * @exception CardException always
74: */
75: public static void throwIt(short reason) throws CardException {
76: throw new CardException(reason);
77: }
78: }
|