<p>I'm trying to catch a ClassCastException when deserializing an object from xml.</p>

<p>So,</p>

<pre><code>try {
    restoredItem = (T) decoder.readObject();
} catch (ClassCastException e){
    //don't need to crash at this point,
   //just let the user know that a wrong file has been passed.
}
</code></pre>

<p>And yet this won't as the exception doesn't get caught. What would you suggest?</p>

Well, I can't use
```
instanceof
```
operator as the method is a parametrized one:
```
```
public T restore(String from){
...
restoredItem = (T) decoder.readObject();
...
}
```
```
And generics in Java are compile-time only.