package umontreal.iro.lecuyer.rng;
/**
* This exception is thrown when a random stream factory cannot instantiate a stream
* on a call to its {@link umontreal.iro.lecuyer.rng.RandomStreamFactory#newInstance(()) newInstance} method.
*
*/
public class RandomStreamInstantiationException extends RuntimeException {
private RandomStreamFactory factory;
/**
* Constructs a new random stream instantiation exception with
* no message, no cause, and thrown by the given factory.
*
* @param factory the random stream factory which thrown the exception.
*
*
*/
public RandomStreamInstantiationException (RandomStreamFactory factory) {
super();
this.factory = factory;
}
/**
* Constructs a new random stream instantiation exception with
* the given message, no cause, and concerning factory.
*
* @param factory the random stream factory concerned by the exception.
*
* @param message the error message describing the exception.
*
*
*/
public RandomStreamInstantiationException (RandomStreamFactory factory,
String message) {
super (message);
this.factory = factory;
}
/**
* Constructs a new random stream instantiation exception with
* no message, the given cause, and concerning factory.
*
* @param factory the random stream factory concerned by the exception.
*
* @param cause the cause of the exception.
*
*
*/
public RandomStreamInstantiationException (RandomStreamFactory factory,
Throwable cause) {
super (cause);
this.factory = factory;
}
/**
* Constructs a new random stream instantiation exception with
* the given message, the supplied cause,
* and concerning factory.
*
* @param factory the random stream factory concerned by the exception.
*
* @param message the error message describing the exception.
*
* @param cause the cause of the exception.
*
*
*/
public RandomStreamInstantiationException (RandomStreamFactory factory,
String message, Throwable cause) {
super (message, cause);
this.factory = factory;
}
/**
* Returns the random stream factory concerned by this exception.
*
* @return the random stream factory concerned by this exception.
*
*/
public RandomStreamFactory getRandomStreamFactory() {
return factory;
}
/**
* Returns a short description of the exception.
* If {@link #getRandomStreamFactory(()) getRandomStreamFactory} returns null,
* this calls super.toString. Otherwise, the
* result is the concatenation of:
*
* a) the name of the actual class of the exception;
*
* b) the string ": For random stream factory ";
*
* c) the result of {@link #getRandomStreamFactory(()) getRandomStreamFactory}.toString();
*
* d) if {@link java.lang.Throwable#getMessage(()) getMessage} is non-null,
* ", " followed by the result of
* {@link java.lang.Throwable#getMessage(()) getMessage}.
*
* @return a string representation of the exception.
*/
public String toString() {
if (factory == null)
return super.toString();
StringBuffer sb = new StringBuffer (getClass().getName());
sb.append (": For random stream factory ");
sb.append (factory.toString());
String msg = getMessage();
if (msg != null)
sb.append (", ").append (msg);
return sb.toString();
}
}
Ads help maintain this website.