"tryparse / parse like" pattern: best proceed exercise it
this doubt follow-up . xxx() tryxxx() settlement something unequivocally useful libraries. i am wondering best proceed offer both implementations but duplicating code.
what best:
public int dosomething(string a)
{
// competence pitch an exception
}
public bool trysomething(string a, out result)
{
try
{
outcome = dosomething(a)
relapse true;
}
locate (exception)
{
relapse false;
}
or
public int dosomething(string a)
{
int result;
(trysomething(a, out result))
{
relapse result;
}
else
{
pitch exception(); // exception?
}
}
public bool trysomething(string a, out result)
{
//...
}
i'd instinctively assume initial instance some-more repremand (you know accurately difference happened), nonetheless couldn't try/catch too expensive? there proceed locate difference second example?
Comments
Post a Comment