I am trying to implement lambda expression for constructor. My constructor can throw an IllegalArgumentException. I tried different ways. First way is just calling lambda expression:
catchThrowable(() -> new SomeClass(testVar1, null, testVar2));
It works perfectly fine, I can catch Exception and then parse it. The problem occurs when I try to use my own interface:
interface SomeClassFactory{
SomeClass create (String testVar1, String persId, String testVar2) throws IllegalArgumentException;
}
SomeClassFactory factory = SomeClass::new;
and then I use it as:
catchThrowable((ThrowableAssert.ThrowingCallable) factory.create(testVar1, null, testVar3));
But the last line of code does not catch any exceptions, my code gives runtime exception and stops. Can you please explain why it happens and, if possible, how to fix it?