OSDN Git Service

X.690 Amendment1 (10/2003)
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / exception / ASN1Exception.java
1 /*
2  * Copyright 2011-2012 BitMeister Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package jp.bitmeister.asn1.exception;
17
18 import jp.bitmeister.asn1.type.ASN1Type;
19
20 /**
21  * The general exception that related to this library and should be caught.
22  * 
23  * @author WATANABE, Jun. <jwat at bitmeister.jp>
24  */
25 @SuppressWarnings("serial")
26 public class ASN1Exception extends Exception {
27
28         protected DetailedMessage message;
29
30         /**
31          * Set detailed message of this exception.
32          * 
33          * @param description
34          *            The description of this exception.
35          * @param cause
36          *            The cause exception of this exception.
37          * @param type
38          *            The ASN.1 type related to this exception.
39          * @param element
40          *            The element name related to this exception.
41          * @param data
42          *            The ASN.1 data related to this exception.
43          */
44         public void setMessage(String description, Throwable cause,
45                         Class<? extends ASN1Type> type, String element, ASN1Type data) {
46                 message = new DetailedMessage(description, cause, type, element, data);
47         }
48
49         /*
50          * (non-Javadoc)
51          * 
52          * @see java.lang.Throwable#getMessage()
53          */
54         @Override
55         public String getMessage() {
56                 if (message != null) {
57                         return message.getMessage();
58                 }
59                 return super.getMessage();
60         }
61
62         /*
63          * (non-Javadoc)
64          * 
65          * @see java.lang.Throwable#getCause()
66          */
67         @Override
68         public Throwable getCause() {
69                 return message.getCause();
70         }
71
72 }