Hi Folks!
I was pondering over a code and noticed that exception handlers were
present in the private, protected as well as public methods. And,
ofcourse, public methods were calling priv/prot methods internally.
My thought was, the exception is being rethrown and propagated by the
non-public methods to the public methods, causing performance overhead
(stack winding etc).
I do agree that, the purpose of throwing the exception by internal
methods and the need for such exception in public methods is the
deciding factor.
But, won't it be better to avoid using try-catch handlers in non-public
methods and rather handle these exceptions only in public methods.
Commonly, folks do use try-catch handler in every non-public
method(generall y thought of as a safety measure!).
So, wouldn't it be appropriate to have try-catch handlers in public
methods alone and avoid the catch-rethrow practice in non-public
methods?
TIA>
Sek.
I was pondering over a code and noticed that exception handlers were
present in the private, protected as well as public methods. And,
ofcourse, public methods were calling priv/prot methods internally.
My thought was, the exception is being rethrown and propagated by the
non-public methods to the public methods, causing performance overhead
(stack winding etc).
I do agree that, the purpose of throwing the exception by internal
methods and the need for such exception in public methods is the
deciding factor.
But, won't it be better to avoid using try-catch handlers in non-public
methods and rather handle these exceptions only in public methods.
Commonly, folks do use try-catch handler in every non-public
method(generall y thought of as a safety measure!).
So, wouldn't it be appropriate to have try-catch handlers in public
methods alone and avoid the catch-rethrow practice in non-public
methods?
TIA>
Sek.
Comment