2

I have the following situation:

public class MyHandler extends DefaultHandler {
    public class CustomException extends SAXException {

    }
}

Eclipse is telling me that SAXException is serializable, and that I should either add a serialVersionUID to CustomException or suppress the warnings.

Questions:

  1. Why does such exception implement serializable?
  2. CustomException is empty. Should I add a serialVersionUID or suppress the warnings?


Related problem (less important): why does Eclipse always tell me that a serialVersionUID is missing, even when I add one?

0x5C91
  • 3,360
  • 3
  • 31
  • 46
  • 1) If any class implement serializable interface then reason is same 2) Suppress it – Kick Feb 26 '14 at 16:50
  • 1
    I've never understood the warning before but here's a good question on it: http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it – Embattled Swag Feb 26 '14 at 16:54

1 Answers1

3

1 All exceptions are Serializable because Throwable, the super class for all exceptions, is Serializable. It is used in RMI, if a remote method throws an exception this exception will be returned to client using serialization

2 You can do both, if you are not going to serialize your custom exception, it makes no difference

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Could you provide a case when I would want to serialize an exception? Is it correct to say that, because I'm not going to serialize mine, suppressing the warnings is more correct because it won't deceive future readers of my code? – 0x5C91 Feb 26 '14 at 16:54
  • 2
    One case is RMI, I added it to my answer – Evgeniy Dorofeev Feb 26 '14 at 16:54