I have the following code:
Type1 Method1(Type2 p)
{
try
{
return DoSomething(p)
}
catch{ExceptionType1}
{
}
catch{ExceptionType2}
{
}
catch{ExceptionType3}
{
}
}
Type3 Method2(Type4 p)
{
try
{
return DoSomethingElse(p)
}
catch{ExceptionType1}
{
}
catch{ExceptionType2}
{
}
catch{ExceptionType3}
{
}
}
How can i refactor this code to have something like:
TResult ExceptionalMethod(Methodx(T)){
try
{
return Methodx(T);
}
catch{ExceptionType1}
{
}
catch{ExceptionType2}
{
}
catch{ExceptionType3}
{
}
}
Thank you,
Adrya
This would work:
I do hope you do something useful in those catches.
EDIT
If you don’t have the
Func<T, TResult>delegate in your version of the framework, you can easily add it, nothing special to it: