All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ssf4j.Exceptions Maven / Gradle / Ivy

There is a newer version: 0.4
Show newest version
package org.ssf4j;

/**
 * Utility class for dealing with exceptions
 * @author robin
 *
 */
public class Exceptions {

	/**
	 * Convert the argument to a {@link RuntimeException} so it can be thrown.
	 * 
    *
  1. If the argument is an {@link Error} then rethrow it immediately.
  2. *
  3. If the argument is already a RuntimeException, return it.
  4. *
  5. Finally, wrap the argument in a RuntimeException and return it.
  6. *
* @param t * @param message * @return */ public static RuntimeException runtime(Throwable t) { return runtime(t, null); } /** * Convert the argument to a {@link RuntimeException} so it can be thrown. *
    *
  1. If the argument is an {@link Error} then rethrow it immediately.
  2. *
  3. If a message is supplied, wrap the argument in a RuntimeException with * the message and return it.
  4. *
  5. If a message is not supplied but the argument is already a RuntimeException, * return it.
  6. *
  7. Finally, wrap the argument in a RuntimeException and return it.
  8. *
* *
{@code
	 * try {
	 *     // do something
	 * } catch(Throwable t) {
	 *     throw Exceptions.runtime(t, "It didn't work.");
	 * }
	 * }
* * * @param t * @param message * @return */ public static RuntimeException runtime(Throwable t, String message) { if(t instanceof Error) throw (Error) t; if(message != null) return new RuntimeException(message, t); if(t instanceof RuntimeException) return (RuntimeException) t; return new RuntimeException(t); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy