I want to write a class method that returns a value, if the class method has an exception then it will be returned. I'm confused how to decide the class structure for this situation. What I am thinking about is that method returning an Object, if the method executes successfully then it returns a value otherwise an Exception message.
class ABC
{
public Object xxx(int a,int b)
{
Object returnValue=null;
try{retunValue=a/b;}
catch(Excetion e){returnValue=e;}
return returnValue;
}
}
Is it the correct way, I was also thinking about setXXX
and getXXX
methods, but this will not help me for this situation. Please help me, what is the correct approach to follow.
Thanks