My Activity holds a member member_one which holds another member member_two which can throw an Exception. I need to show user a Toast if this Exception happens. In order to show a Toast I need to throw Exception from member_tow to member_one and then from member_one to my Activity. This approach leads to big changes and I don’t want to do so. May be I just think wrong, is there any easy way to handle the exception?
My Activity holds a member member_one which holds another member member_two which can throw
Share
So far I know there will be two solutions of the problem.
Contextto youmember_one,member_twoand then use thatContextto make Toast.Like Toast.makeText(mContext, "Exception Occurred", Toast.LENGTH_SHORT).show();Second approach will be through
Interface-Make a
Interfacemethod in your class ofmember_oneand so onlike
and when ever you get
ExceptioncallonError.whatIsErr(e.toString());and in main
ActivityHow other programmers know if they want to use one of these classes they need to set listeners?
Well for this you force the constructor to pass a listener.
Like