views:

44

answers:

1

Hi All,

I need to change an existing service API to throw an extra exception for a scenario. The exception will be a subtype of an already thrown exception. Is it okay to do this or will it be considered backwards incompatible?

I have the interface in a separate jar, so if my service throws this new exception which is a child of the already thrown one and the client does not have the new jar, will it break the client or will he be able to still catch the parent exception like before?

The problem is we have a very generic exception that is thrown for every exceptional case and some clients want better ways to identify the exception - apart from parsing the message in the exception, but not all clients may upgrade the interface if we introduce a new exception - how best to handle this scenario?

Thanks Arvind

+1  A: 

As the new exception is a sub-type of an existing one, you shouldn't break any existing code. If the client code traps the base exception it will trap your new one.

You can then refactor the client code to trap the newer more specific exception.

ChrisF
I thought that if the new subtype object is not in the jar the client has, he would get a ClassNotFoundException or something like that
Arvind
@Arvind - the best way to test this sort of thing out is to set up a test application and make the edit there to see what happens.
ChrisF