T
Tom Ewall
Given the need for a method to handle the message for a given
exception, where should that logic be placed? (that is, the logic for
the creation of the message is non-trival, depending on, for the
example I'm giving here, on the String "parm" which is passed in) One
solution would be to put it in the exception class itself, as a static
method. Another solution would be to put it somewhere else, like some
sort of utility class. To make clear my question, here are a couple
of examples:
1) throw new MyException( MyException.getMessageForMyException( parm )
);
2) throw new MyException( UtilityClass.getMessageForMyException( parm
) );
My inclination would be to not put the getMessageForMyException( )
method in the exception class itself (i.e. MyException), however when
asked about why not, I couldn't give a good reason.
exception, where should that logic be placed? (that is, the logic for
the creation of the message is non-trival, depending on, for the
example I'm giving here, on the String "parm" which is passed in) One
solution would be to put it in the exception class itself, as a static
method. Another solution would be to put it somewhere else, like some
sort of utility class. To make clear my question, here are a couple
of examples:
1) throw new MyException( MyException.getMessageForMyException( parm )
);
2) throw new MyException( UtilityClass.getMessageForMyException( parm
) );
My inclination would be to not put the getMessageForMyException( )
method in the exception class itself (i.e. MyException), however when
asked about why not, I couldn't give a good reason.