Skip to content

Commit f7e1454

Browse files
committed
Now that we are on Java 1.4, we can save the original exception when we re-throw another exception.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@797688 13f79535-47bb-0310-9956-ffa450edef68
1 parent 91a01c9 commit f7e1454

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

src/java/org/apache/commons/codec/EncoderException.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
package org.apache.commons.codec;
1919

2020
/**
21-
* Thrown when there is a failure condition during the encoding process. This
22-
* exception is thrown when an Encoder encounters a encoding specific exception
23-
* such as invalid data, inability to calculate a checksum, characters outside of the
24-
* expected range.
21+
* Thrown when there is a failure condition during the encoding process. This exception is thrown when an Encoder
22+
* encounters a encoding specific exception such as invalid data, inability to calculate a checksum, characters outside
23+
* of the expected range.
2524
*
2625
* @author Apache Software Foundation
2726
* @version $Id$
@@ -38,10 +37,36 @@ public class EncoderException extends Exception {
3837
/**
3938
* Creates a new instance of this exception with an useful message.
4039
*
41-
* @param message a useful message relating to the encoder specific error.
40+
* @param message
41+
* a useful message relating to the encoder specific error.
4242
*/
4343
public EncoderException(String message) {
4444
super(message);
4545
}
46-
}
4746

47+
/**
48+
* Creates a EncoderException.
49+
*
50+
* @param cause
51+
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
52+
* value is permitted, and indicates that the cause is nonexistent or unknown.
53+
* @since 1.4
54+
*/
55+
public EncoderException(Throwable cause) {
56+
super(cause);
57+
}
58+
59+
/**
60+
* Creates a EncoderException.
61+
*
62+
* @param message
63+
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
64+
* @param cause
65+
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
66+
* value is permitted, and indicates that the cause is nonexistent or unknown.
67+
* @since 1.4
68+
*/
69+
public EncoderException(String message, Throwable cause) {
70+
super(message, cause);
71+
}
72+
}

src/java/org/apache/commons/codec/binary/Hex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public Object encode(Object object) throws EncoderException {
221221
byte[] byteArray = object instanceof String ? ((String) object).getBytes() : (byte[]) object;
222222
return encodeHex(byteArray);
223223
} catch (ClassCastException e) {
224-
throw new EncoderException(e.getMessage());
224+
throw new EncoderException(e.getMessage(), e);
225225
}
226226
}
227227

src/java/org/apache/commons/codec/net/BCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String encode(final String value, final String charset) throws EncoderExc
108108
try {
109109
return encodeText(value, charset);
110110
} catch (UnsupportedEncodingException e) {
111-
throw new EncoderException(e.getMessage());
111+
throw new EncoderException(e.getMessage(), e);
112112
}
113113
}
114114

src/java/org/apache/commons/codec/net/QCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public String encode(final String pString, final String charset) throws EncoderE
190190
try {
191191
return encodeText(pString, charset);
192192
} catch (UnsupportedEncodingException e) {
193-
throw new EncoderException(e.getMessage());
193+
throw new EncoderException(e.getMessage(), e);
194194
}
195195
}
196196

src/java/org/apache/commons/codec/net/QuotedPrintableCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public String encode(String pString) throws EncoderException {
255255
try {
256256
return encode(pString, getDefaultCharset());
257257
} catch (UnsupportedEncodingException e) {
258-
throw new EncoderException(e.getMessage());
258+
throw new EncoderException(e.getMessage(), e);
259259
}
260260
}
261261

src/java/org/apache/commons/codec/net/URLCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public String encode(String pString) throws EncoderException {
244244
try {
245245
return encode(pString, getDefaultCharset());
246246
} catch (UnsupportedEncodingException e) {
247-
throw new EncoderException(e.getMessage());
247+
throw new EncoderException(e.getMessage(), e);
248248
}
249249
}
250250

0 commit comments

Comments
 (0)