I have to write a FTP (AUTH TSL) framework in C#. I'm a noob at writing frameworks.
E.g. when I prove that a file exists and it doesn't, what should I do?
What is professional in this case?
Broad question actually, but there are some clues to get you on the way:
Console.WriteLine() or any stuff like that in a framework.Framework.FileExists, if file doesn't exist, simply return false value. That's the true nature of the Boolean return value. That's more semantic.ArgumentNullException.To pass an "error code" back as return value, it is common to use enums. Your upload method could return
public enum UploadResult
{
Success,
PasswordInvalid,
UserInvalid,
FileNotFound,
HostNotFound
}
The user of your framework then can easily use it like this:
if (Ftp.Upload(User, Pass, Host, File) != UploadResult.Success)
{
MessageBox.Show("Sorry, something went terribly wrong.");
}
or check for more specific reasons and try again.
Edit: And as written in my comment to your original posting: If something really unexpected happens or the user input is clearly invalid, throw an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With