blah blah blah is here! blah blah » Close

up0down
link

hi,
I have a class A that has three methods, M1, M2 and M3
M1 is the caller of M2 and M3.
M2 and M3 throws exceptions.
this method M1 is called by class B from it;s method P1,
Should i write any code in M1 to handle exception thrown by M2 and M3 or i only have to place a try /catch in P1?
cheers

last answered 2 years ago

1 answers

up0down
link

Ideally you'd handle it in M1() as it is the caller of those exception raising methods. But it depends on the kind of exceptions they are. If M1() took in arguments from the callee, passed it into the helper methods M2() and/or M3(), which in turn raises the exception, it should be handled by the callee of M1(). But if the exception raised is due to input from M1(), M1() should be the one to handle that exception.

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback