Custom Exception with generic type
<p>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.</p>

<p>But the problem is listOfFailedRecords has to be generic. </p>

<p>Something like, </p>

<pre><code>throw new MyException("Failed due to dependency", listOfFailedRecords)
</code></pre>

<p>And the MyException class would look like,</p>

<pre><code>public class MyException&lt;T&gt; extends Exception {
    List&lt;T&gt; listOfFailedRecords;
    MyException(String message, List&lt;T&gt; listOfFailedRecords) {
        super(message);
        this.listOfFailedRecords = listOfFailedRecords;
    }
}
</code></pre>

<p>But the problem is Java doesn't allow generic class to extend Exception class.</p>

<p>What should be the approach now?
Should I pass a list of Objects to this exception as </p>

<pre><code>List&lt;Object&gt; listOfFailedRecords
</code></pre>

<p>Or is there a better way?</p>