task2/solution10/src/org/apidesign/apifest08/currency/CurrencyConversionException.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 6 task1/solution10/src/org/apidesign/apifest08/currency/CurrencyConversionException.java@97662396c0fd
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
japod@6
     1
package org.apidesign.apifest08.currency;
japod@6
     2
japod@6
     3
import java.util.*;
japod@6
     4
japod@6
     5
/**
japod@6
     6
 * Exception thrown in cases that a CurrencyConverter is unable ensure requested accuracy of conversion.
japod@6
     7
 * Such situation may occur in cases that the client is not on-line, or the exchange rates are older than
japod@6
     8
 * requested etc. This exception is defined as RuntimeException to enable simple usage in simple applications,
japod@6
     9
 * but enable other applications to be informed about possible problems and prevent them from using
japod@6
    10
 * inaccurate data.
japod@6
    11
 */
japod@6
    12
public final class CurrencyConversionException extends RuntimeException {
japod@6
    13
japod@6
    14
	private final Currency from;
japod@6
    15
	private final Currency to;
japod@6
    16
japod@6
    17
	CurrencyConversionException(Currency from, Currency to) {
japod@6
    18
		this(from, to, (Throwable) null);
japod@6
    19
	}
japod@6
    20
japod@6
    21
	CurrencyConversionException(Currency from, Currency to, Throwable throwable) {
japod@6
    22
		this(from, to, String.format("Failed to convert curency from %1$s to %2$s", from, to), throwable);
japod@6
    23
	}
japod@6
    24
japod@6
    25
	CurrencyConversionException(Currency from, Currency to, String message) {
japod@6
    26
		this(from, to, message, null);
japod@6
    27
	}
japod@6
    28
japod@6
    29
	CurrencyConversionException(Currency from, Currency to, String message, Throwable throwable) {
japod@6
    30
		super(message, throwable);
japod@6
    31
		this.from = from;
japod@6
    32
		this.to = to;
japod@6
    33
	}
japod@6
    34
japod@6
    35
	public Currency getFromCurrency() {
japod@6
    36
		return from;
japod@6
    37
	}
japod@6
    38
japod@6
    39
	public Currency getToCurrency() {
japod@6
    40
		return to;
japod@6
    41
	}
japod@6
    42
}