Xceed .NET Libraries Documentation
Exceptions

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Exceptions

An exception is any error condition or unexpected behavior encountered by an executing program. Whenever an error occurs, an Exception object is created to represent the exception.

Handling exceptions.

The exceptions that can be thrown by Xceed Zip for .NET are handled in the same manner as regular run-time exceptions using Try/Catch blocks. It is possible to intercept the exceptions before they are thrown using the ItemException event in order to try and recover from the exception before it is actually thrown. 

Whenever you contact technical support regarding an exception, please include the ToString() result of the exception. 

The following table provides a listing of all the custom exceptions that can be thrown when an error occurs: 

Exception Description
FileSystemException Exception that is thrown when an error occurs in the Xceed.FileSystem namespace.
FileSystemInternalException Exception that is thrown when something unexpected occurs in the Xceed.FileSystem namespace.
FileSystemIOException Exception that is thrown when an IO error occurs while reading from or writing to an AbstractFile object.
ItemAlreadyExistsException Exception that is thrown when performing an operation on a FileSystemItem object that already exists.
ItemDoesNotExistException Exception that is thrown when performing an operation on a FileSystemItem object that does not yet exist.
ItemIsReadOnlyException Exception that is thrown when performing an operation on a FileSystemItem object that is read only.
ItemIsRootFolderException Exception that is thrown when performing an operation on a FileSystemItem object that is a root folder that does not permit that operation.
InvalidDecryptionPasswordException Exception that is thrown when the data could not be decrypted with the supplied decryption password.
InvalidZipStructureException Exception that is thrown when the internal structure of a ZIP file is invalid.
InvalidSfxModuleException Exception that is thrown when an invalid SFX binary is provided.
ZipException Exception that is thrown when an error occurs in the Xceed.Zip namespace.
ZipIOException Exception that is thrown when an IO exception occurs while reading from or writing to the ZIP file.
QuickZipException Exception that is thrown when an error occurs in a method of the QuickZip class
InvalidTarStructureException Exception that is thrown when the internal structure of a tar file is invalid. This exception is not available in Xceed's .NET Compact Framework products.
InvalidGZipStructureException Exception that is thrown when the internal structure of a gzip file is invalid. This exception is not available in Xceed's .NET Compact Framework products.
CompressionException Exception that is thrown when there is a problem compressing or decompressing data.
CompressionInternalException Exception that is thrown when something unexpected occurs while compressing or decompressing data.

The ZipException class derives directly from the FileSystemException class. All of the other exception classes defined within the Xceed.Zip namespace derive from the ZipException class.

Demonstration

The following example demonstrates how to use a Try/Catch statement when calling the Delete method on a ZippedFile that is contained within a corrupted zip file:

VB.NET Copy Code
Try
   Dim f As New ZippedFile( New DiskFile( "c:\test.zip" ), "\file.txt" )
   f.Delete()
Catch err As ZipException
   ListBox1.Items.Add( err.Message ) 
End Try
C# Copy Code
try
{
   ZippedFile f = new ZippedFile( new DiskFile( @"c:\test.zip" ), @"\file.txt" );
   f.Delete();
}
catch( ZipException err )
{
   Console.WriteLine( err.Message );
}

Things you should consider

The main questions you should ask yourself when handling exceptions are:

  • Do you want to intercept the exceptions before they are thrown? See the ItemException event topic.