public final class Throw extends Object
if (Double.isNaN(gtu.getPosition.si))
{
throw new GTUException("position is NaN for GTU " + gtu.getId());
}
we can write:
Throw.when(Double.isNaN(gtu.getPosition.si), GTUException.class, "position is NaN for GTU %s", gtu.getId());
Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
when(boolean condition,
Class<T> throwableClass,
String message)
Throw a Throwable (such as an Exception or Error) if a condition is met, e.g.
|
static <T extends Throwable> |
when(boolean condition,
Class<T> throwableClass,
String message,
Object arg)
Throw a Throwable (such as an Exception or Error) if a condition is met, e.g.
|
static <T extends Throwable> |
when(boolean condition,
Class<T> throwableClass,
String message,
Object arg1,
Object arg2)
Throw a Throwable (such as an Exception or Error) if a condition is met, e.g.
|
static <T extends Throwable> |
when(boolean condition,
Class<T> throwableClass,
String message,
Object arg1,
Object arg2,
Object arg3)
Throw a Throwable (such as an Exception or Error) if a condition is met, e.g.
|
static <T extends Throwable> |
when(boolean condition,
Class<T> throwableClass,
String message,
Object arg1,
Object arg2,
Object arg3,
Object... args)
Throw a Throwable (such as an Exception or Error) if a condition is met, e.g.
|
static void |
whenNull(Object object,
String message)
Throw a NullPointerException if object is null, e.g.
|
static void |
whenNull(Object object,
String message,
Object arg)
Throw a NullPointerException if object is null, e.g.
|
static void |
whenNull(Object object,
String message,
Object arg1,
Object arg2)
Throw a NullPointerException if object is null, e.g.
|
static void |
whenNull(Object object,
String message,
Object arg1,
Object arg2,
Object arg3)
Throw a NullPointerException if object is null, e.g.
|
static void |
whenNull(Object object,
String message,
Object arg1,
Object arg2,
Object arg3,
Object... args)
Throw a NullPointerException if object is null, e.g.
|
public static <T extends Throwable> void when(boolean condition, Class<T> throwableClass, String message) throws T extends Throwable
Throw.when(value == null, GTUException.class, "value cannot be null");
TODO this example is badly chosen; to test for null; call whenNull.T - the Throwable typecondition - the condition to check; an exception will be thrown if this is truethrowableClass - the Throwable type to throwmessage - the message to use in the exceptionT - the throwable to throw on true conditionT extends Throwablepublic static <T extends Throwable> void when(boolean condition, Class<T> throwableClass, String message, Object arg) throws T extends Throwable
Throw.when(value == null, GTUException.class, "value cannot be null for GTU with id = %s", id);T - the Throwable typecondition - the condition to check; an exception will be thrown if this is truethrowableClass - the Throwable type to throwmessage - the message to use in the exception, with formatting identifiersarg - value to use for the formatting identifiersT - the throwable to throw on true conditionT extends Throwablepublic static <T extends Throwable> void when(boolean condition, Class<T> throwableClass, String message, Object arg1, Object arg2) throws T extends Throwable
Throw.when(value == null, GTUException.class, "value cannot be null for GTU %s with id %s", name, id);T - the Throwable typecondition - the condition to check; an exception will be thrown if this is truethrowableClass - the Throwable type to throwmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersT - the throwable to throw on true conditionT extends Throwablepublic static <T extends Throwable> void when(boolean condition, Class<T> throwableClass, String message, Object arg1, Object arg2, Object arg3) throws T extends Throwable
Throw.when(value == null, GTUException.class, "value cannot be null for GTU %s with id %s", name, id);T - the Throwable typecondition - the condition to check; an exception will be thrown if this is truethrowableClass - the Throwable type to throwmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersarg3 - 3rd value to use for the formatting identifiersT - the throwable to throw on true conditionT extends Throwablepublic static <T extends Throwable> void when(boolean condition, Class<T> throwableClass, String message, Object arg1, Object arg2, Object arg3, Object... args) throws T extends Throwable
Throw.when(value == null, GTUException.class, "value cannot be null for GTU with id = %s", id);T - the Throwable typecondition - the condition to check; an exception will be thrown if this is truethrowableClass - the Throwable type to throwmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersarg3 - 3rd value to use for the formatting identifiersargs - potential 4th and further values to use for the formatting identifiersT - the throwable to throw on true conditionT extends Throwablepublic static void whenNull(Object object, String message) throws NullPointerException
Throw.whenNull(value, "value cannot be null");object - object to check; an exception will be thrown if this is nullmessage - the message to use in the exceptionNullPointerException - if object is nullpublic static void whenNull(Object object, String message, Object arg) throws NullPointerException
Throw.whenNull(value, "value cannot be null for GTU with id = %s", id);object - object to check; an exception will be thrown if this is nullmessage - the message to use in the exception, with formatting identifiersarg - value to use for the formatting identifiersNullPointerException - if object is nullpublic static void whenNull(Object object, String message, Object arg1, Object arg2) throws NullPointerException
Throw.whenNull(value, "value cannot be null for GTU %s with id %s", name, id);object - object to check; an exception will be thrown if this is nullmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersNullPointerException - if object is nullpublic static void whenNull(Object object, String message, Object arg1, Object arg2, Object arg3) throws NullPointerException
Throw.whenNull(value, "value cannot be null for GTU %s with id %s", name, id);object - object to check; an exception will be thrown if this is nullmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersarg3 - 3rd value to use for the formatting identifiersNullPointerException - if object is nullpublic static void whenNull(Object object, String message, Object arg1, Object arg2, Object arg3, Object... args) throws NullPointerException
Throw.whenNull(value, "value cannot be null for GTU %s with id %s", name, id);object - object to check; an exception will be thrown if this is nullmessage - the message to use in the exception, with formatting identifiersarg1 - 1st value to use for the formatting identifiersarg2 - 2nd value to use for the formatting identifiersarg3 - 3rd value to use for the formatting identifiersargs - potential 4th and further values to use for the formatting identifiersNullPointerException - if object is nullCopyright © 2014–2016 Delft University of Technology. All rights reserved.