I wish there was more an interface could do. Like enforce a method to handle a specific type of exception. Maybe it could be done with attributes. Something that would look like this:
public interface IFileManipulation
{
[RequiredExceptionAttribute(System.IO.FileNotFoundException)]
bool Delete(string FileName);
[RequiredExceptionAttribute(System.IO.DriveNotFoundException)]
bool Save(string FileName);
}
public class DataFileHelper : IFileManipulation
{
#region IFileManipulation Members
public bool Delete(string FileName)
{
try
{
throw new System.Exception("The method or operation is not implemented.");
}
catch (System.IO.FileNotFoundException FileNotFoundException)
{
throw FileNotFoundException;
}
}
public bool Save(string FileName)
{
try
{
throw new System.Exception("The method or operation is not implemented.");
}
catch (System.IO.DriveNotFoundException DriveNotFoundException)
{
throw DriveNotFoundException;
}
}
#endregion
}
I know you can enforce exception handling using FxCop, but it takes so long to set up and I like the automatic code population that interfaces provide. Dave Donaldson is the attribute man, maybe he can provide some guidance.