task1/solution10/src/org/apidesign/apifest08/currency/CurrencyConversionException.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task1/solution10/src/org/apidesign/apifest08/currency/CurrencyConversionException.java Sun Sep 28 14:12:38 2008 +0200
1.3 @@ -0,0 +1,42 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +import java.util.*;
1.7 +
1.8 +/**
1.9 + * Exception thrown in cases that a CurrencyConverter is unable ensure requested accuracy of conversion.
1.10 + * Such situation may occur in cases that the client is not on-line, or the exchange rates are older than
1.11 + * requested etc. This exception is defined as RuntimeException to enable simple usage in simple applications,
1.12 + * but enable other applications to be informed about possible problems and prevent them from using
1.13 + * inaccurate data.
1.14 + */
1.15 +public final class CurrencyConversionException extends RuntimeException {
1.16 +
1.17 + private final Currency from;
1.18 + private final Currency to;
1.19 +
1.20 + CurrencyConversionException(Currency from, Currency to) {
1.21 + this(from, to, (Throwable) null);
1.22 + }
1.23 +
1.24 + CurrencyConversionException(Currency from, Currency to, Throwable throwable) {
1.25 + this(from, to, String.format("Failed to convert curency from %1$s to %2$s", from, to), throwable);
1.26 + }
1.27 +
1.28 + CurrencyConversionException(Currency from, Currency to, String message) {
1.29 + this(from, to, message, null);
1.30 + }
1.31 +
1.32 + CurrencyConversionException(Currency from, Currency to, String message, Throwable throwable) {
1.33 + super(message, throwable);
1.34 + this.from = from;
1.35 + this.to = to;
1.36 + }
1.37 +
1.38 + public Currency getFromCurrency() {
1.39 + return from;
1.40 + }
1.41 +
1.42 + public Currency getToCurrency() {
1.43 + return to;
1.44 + }
1.45 +}