![JAR search and dependency download from the Maven repository](/logo.png)
org.cthul.strings.Exceptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cthul-strings Show documentation
Show all versions of cthul-strings Show documentation
Functions for converting strings from and to various formats,
such as roman numbers, alpha indices, Java identifiers,
and format strings.
The newest version!
package org.cthul.strings;
import org.cthul.strings.format.FormatterConfiguration;
/**
* Helper for creating formatted exceptions.
*/
public class Exceptions {
public static T create(FormatterConfiguration c, Factory f, String msg, Object... args) {
String m = msg(c, msg, args);
Throwable t = t(args);
return f.create(m, t);
}
protected static String msg(FormatterConfiguration c, String msg, Object[] args) {
String m = Strings.format(c, msg, args);
return m;
}
protected static Throwable t(Object[] args) {
Throwable t = args.length > 0 && args[0] instanceof Throwable ? (Throwable) args[0] : null;
return t;
}
public static interface Factory {
T create(String message, Throwable cause);
}
public static final Factory RUNTIME_EXCEPTION = new Factory() {
@Override
public RuntimeException create(String message, Throwable cause) {
return new RuntimeException(message, cause);
}
};
public static final Factory ILLEGAL_ARGUMENT = new Factory() {
@Override
public IllegalArgumentException create(String message, Throwable cause) {
return new IllegalArgumentException(message, cause);
}
};
public static final Factory ILLEGAL_STATE = new Factory() {
@Override
public IllegalStateException create(String message, Throwable cause) {
return new IllegalStateException(message, cause);
}
};
public static final Factory UNSUPPORTED_OPERATION = new Factory() {
@Override
public UnsupportedOperationException create(String message, Throwable cause) {
return new UnsupportedOperationException(message, cause);
}
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy