I have wrapped the Exception in my java class into a custom exception. I want my custom exception to receive two parameters, one the message and second a list.
But the problem is listOfFailedRecords has to be generic.
Something like,
throw new MyException("Failed due to dependency", listOfFailedRecords)
And the MyException class would look like,
public class MyException<T> extends Exception {
List<T> listOfFailedRecords;
MyException(String message, List<T> listOfFailedRecords) {
super(message);
this.listOfFailedRecords = listOfFailedRecords;
}
}
But the problem is Java doesn't allow generic class to extend Exception class.
What should be the approach now? Should I pass a list of Objects to this exception as
List<Object> listOfFailedRecords
Or is there a better way?