I am writing an application and I want to download a file based on the path provided by the user. I check the file extension and when the extension does not match anything that I recognize, I want to throw an exception.
I could throw it away IOException. But I thought there might be a more detailed exception to this. So I looked at MSDN and found FileLoadException. The name suggests that my error will fit this category, but .... when I look at MSDN, it says: "Represents the error that occurs when the assembly file is found but cannot be loaded." and "An exception that is thrown when a managed assembly is found but cannot be loaded." This is absolutely not the case with my mistake.
So what is the question? Well, I wonder if the documentation really means that the exception is only for this purpose, or that they simply mean that they throw this exception in this particular case, but do not really indicate when others should throw it.
On a page IOExceptionon MSDN, he advises using FileLoadException, if necessary:
IOException - the base class for exceptions that occur when accessing information using streams, files and directories.
The base class library includes the following types, each of which is a derived class IOException:
- DirectoryNotFoundException
- EndOfStreamException
- FileNotFoundException
- FileLoadException
- PathTooLongException
Use these types instead of an IOException if necessary.
: IOException FileLoadException ( ).
.