Menu

#15 Throw particular exception instead of java.lang.Exception

open
nobody
None
5
2010-08-31
2010-08-31
No

It would be great if Serializer write(…) and read(..) methods throw not just java.lang.Exception, but some particular type of exception (kind of ‘ SerializationException’ or something like that).

In some cases the application should behave differently depending on the exception type. But java.lang.Exception thrown by Serializer overlaps other exceptions which can be thrown by other operators of this piece of code.

For example, there is a method:

public void myMethod(Serialized s) throws Exception {
Operator1;
s.write(…);
Operator2;
Operator3;
….
}

In this example, Operator1, Operator2 and Operator3 may also throw different kinds of exceptions. And in this case it’s impossible to analyse the exception on upper level.

Discussion


Log in to post a comment.