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
     1 package org.apidesign.apifest08.currency;
     2 
     3 import java.util.*;
     4 
     5 /**
     6  * Exception thrown in cases that a CurrencyConverter is unable ensure requested accuracy of conversion.
     7  * Such situation may occur in cases that the client is not on-line, or the exchange rates are older than
     8  * requested etc. This exception is defined as RuntimeException to enable simple usage in simple applications,
     9  * but enable other applications to be informed about possible problems and prevent them from using
    10  * inaccurate data.
    11  */
    12 public final class CurrencyConversionException extends RuntimeException {
    13 
    14 	private final Currency from;
    15 	private final Currency to;
    16 
    17 	CurrencyConversionException(Currency from, Currency to) {
    18 		this(from, to, (Throwable) null);
    19 	}
    20 
    21 	CurrencyConversionException(Currency from, Currency to, Throwable throwable) {
    22 		this(from, to, String.format("Failed to convert curency from %1$s to %2$s", from, to), throwable);
    23 	}
    24 
    25 	CurrencyConversionException(Currency from, Currency to, String message) {
    26 		this(from, to, message, null);
    27 	}
    28 
    29 	CurrencyConversionException(Currency from, Currency to, String message, Throwable throwable) {
    30 		super(message, throwable);
    31 		this.from = from;
    32 		this.to = to;
    33 	}
    34 
    35 	public Currency getFromCurrency() {
    36 		return from;
    37 	}
    38 
    39 	public Currency getToCurrency() {
    40 		return to;
    41 	}
    42 }