If I have a method like the following can I omit the catch block here to achieve the same results?:
private ClassInstance GetMeANumber()
{
Resource a = null;
try
{
Resource a = new Resource();
return a.GetClassInstance();
}
catch
{
throw;
}
finally
{
if(a != null)
a.Dispose();
}
}
Yes, that would be exactly the same.
However, a more common pattern is to implement IDisposable on
Resource. Then you can use using to acheive the same thing more concisely.