Error handling

As with all code, it is recommended that you handle errors. This can be performed using a try/catch block to catch exceptions, and display an appropriate message to the user when necessary.

For example:

System.IO.IOException

For further information of handing IO exceptions, see Microsoft’s guide:
https://learn.microsoft.com/en-us/dotnet/standard/io/handling-io-errors

Sharing violation
This occurs when another piece of software (such as anti-virus or cloud software) accesses the file while Easy Save is trying to access it. There is no way to prevent this from happening, so it is recommended that you inform the user.

Not enough disk space
If the user does not have enough storage left on their device, this exception will be thrown.

Hardware issue
The user’s hardware (such as hard drive) is damaged and unable to perform the IO operation.

System.UnauthorizedAccessException & System.Security.SecurityException

Access to the path x is denied
This occurs when the user doesn’t have the required permissions to save or load to a specific file. Permissions are set by the operating system, so there’s no way to prevent this, so it is recommended that you tell the user.

System.FormatException

The data has been modified or corrupted so is no longer valid
This can occur when the user or an external piece of software tries to modify the file. For example if the user opened the file in a text editor and pressed save, it may try to apply a different encoding to the data which would corrupt it.

Accessing encrypted data when encryption is disabled
This would be considered a coding error, as you should never put the user in a position where they can trigger this error.

System.ArgumentException

Accessing unencrypted data with encryption enabled
This would be considered a coding error, as you should never put the user in a position where they can trigger this error.

The data has been modified/corrupted and is no longer valid
This can occur when the user or an external piece of software tries to modify the file. For example if the user opened the file in a text editor and pressed save, it may try to apply a different encoding to the data which would corrupt it.