In my file repository, I will throw the following exceptions when the InsertFile()
method is called:
Suppose it depends on how you plan on handling exceptions. Throwing specific exceptions lets you respond to them, um, specifically. For instance:
try
{
}
catch(FileSizeExceededException ex)
{
}
catch(StorageCapacityExceededException ex)
{
}
Maybe read the documentation:
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the
ApplicationException
class; however in practice this has not been found to add significant value.
As to whether there are better exceptions to throw - some might consider throwing an ArgumentOutOfRangeException if you don't want to define your own exception.
I would use an ArgumentException
and an InvalidOperationException
, respecitively.
Well what you have so far is alright, but I'd personally throw a System.ArgumentException
(with a detailed message) instead.