javax.money.convert.CurrencyConversionException Maven / Gradle / Ivy
Show all versions of money-api-bp Show documentation
/*
* CREDIT SUISSE IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE
* CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS AGREEMENT.
* PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY. BY
* DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE
* AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE"
* BUTTON AT THE BOTTOM OF THIS PAGE. Specification: JSR-354 Money and Currency
* API ("Specification") Copyright (c) 2012-2013, Credit Suisse All rights
* reserved.
*/
package javax.money.convert;
import javax.money.CurrencyUnit;
import javax.money.MonetaryException;
/**
* Exception thrown when a monetary conversion operation fails.
*
* @author Werner Keil
* @author Stephen Colebourne
* @author Anatole Tresch
*/
public class CurrencyConversionException extends MonetaryException {
/** Serialization lock. */
private static final long serialVersionUID = -7743240650686883450L;
/** Base currency. */
private CurrencyUnit base;
/** Terminating currency. */
private CurrencyUnit term;
/** The acquired {@link ConversionContext}, may be null. */
private ConversionContext conversionContext;
/**
* Constructs an CurrencyConversionException
with the specified
* detail message, timestamp, source and target currency.
*
* @param base
* the source currency, may be null.
*
* @param term
* the target currency, may be null.
*
* @param message
* the detail message.
*/
public CurrencyConversionException(CurrencyUnit base, CurrencyUnit term,
ConversionContext conversionContext, String message) {
super("Cannot convert " + String.valueOf(base) + " into "
+ String.valueOf(term) + ": " + message);
this.base = base;
this.term = term;
this.conversionContext = conversionContext;
}
/**
* Constructs an CurrencyConversionException
with the specified
* source and target currency.
*
* @param base
* the source currency, may be null.
*
* @param term
* the target currency, may be null.
*/
public CurrencyConversionException(CurrencyUnit base, CurrencyUnit term,
ConversionContext conversionContext) {
super("Cannot convert " + String.valueOf(base) + " into "
+ String.valueOf(term));
this.base = base;
this.term = term;
this.conversionContext = conversionContext;
}
/**
* Constructs a new exception with the specified source and target currency,
* detail message and cause.
*
*
* Note that the detail message associated with cause
is
* not automatically incorporated in this exception's detail message.
*
* @param base
* the source currency, may be null.
* @param term
* the target currency, may be null.
* @param message
* the detail message (which is saved for later retrieval by the
* {@link Throwable#getMessage()} method).
* @param cause
* the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A null value
* is permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public CurrencyConversionException(CurrencyUnit base, CurrencyUnit term,
ConversionContext conversionContext, String message, Throwable cause) {
super("Cannot convert " + String.valueOf(base) + " into "
+ String.valueOf(term)
+ (message!=null ? ": " + message : ""), cause);
this.base = base;
this.term = term;
this.conversionContext = conversionContext;
}
/**
* Gets the first currency at fault.
*
* @return the currency at fault, may be null
*/
public CurrencyUnit getBaseCurrency(){
return base;
}
/**
* Gets the second currency at fault.
*
* @return the currency at fault, may be null
*/
public CurrencyUnit getTermCurrency(){
return term;
}
/**
* Gets the queried timestamp at fault.
*
* @return the queried timestamp, or {@code null}.
*/
public ConversionContext getConversionContext() {
return this.conversionContext;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "CurrencyConversionException [base=" + base + ", term=" + term
+ ", conversionContext=" + conversionContext + "]: "
+ getMessage();
}
}