so I have a function which looks like this:
public void addExceptionCommands(Class<? extends Throwable> exClass, Command... commands) {
for (Command command : commands) {
try {
//Push the command to the stack of executed commands
executedCommands.push(command);
command.execute();
} catch (CouldNotExecuteCommandException e) {
// Default strategy is to rollback
rollback();
// Log
e.printStackTrace();
//I want to throw exClass here
}
}
}
I want to throw exClass, how to achieve this? throw exClass does not work
EDIT: Thanks guys for all of the answers, I ended up with using a Supplier :D