package net.anvilcraft.alec.jalec.strategies.implementations; import java.lang.reflect.Constructor; import net.anvilcraft.alec.jalec.IAlecException; import net.anvilcraft.alec.jalec.factories.AlecCriticalRuntimeErrorExceptionFactory; import net.anvilcraft.alec.jalec.strategies.interfaces.IAlecExceptionContructionStrategy; public class StandardConstructorAlecExceptionConstructionStrategy implements IAlecExceptionContructionStrategy { @Override public E constructAlecException(String message, Throwable cause, Class alecExceptionClass) { try { Constructor constructor = alecExceptionClass.getDeclaredConstructor(String.class, Throwable.class); constructor.setAccessible(true); return constructor.newInstance(message, cause); } catch (Exception e) { throw AlecCriticalRuntimeErrorExceptionFactory.PLAIN.createAlecExceptionWithCause( e, "Error while constructing ALEC exception" ); } } }