29 lines
794 B
Java
29 lines
794 B
Java
package org.gcube.resourcemanagement.manager.io.codeexceptions.deserializer;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
/**
|
|
* Deserializer for {@link Exception}.
|
|
*
|
|
* @author Manuele Simi (ISTI CNR)
|
|
*
|
|
*/
|
|
final class ExceptionDeserializer {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private ExceptionDeserializer() {}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
protected static <E extends Exception> E deserialize(String exceptionClass, String message) {
|
|
try {
|
|
final Class<?>[] ctorParams = {String.class};
|
|
return (E) Class.forName(exceptionClass).getConstructor(ctorParams).newInstance(message);
|
|
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|