Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterException Class
See Also  Members   Example 
Leadtools Namespace : RasterException Class



The exception that is thrown when a LEADTOOLS error occurs.

Syntax

Visual Basic (Declaration)  
<SerializableAttribute()>
Public Class RasterException 
   Inherits LeadtoolsException
Visual Basic (Usage) Copy Code
Dim instance As RasterException
C#  
[SerializableAttribute()]
public class RasterException : LeadtoolsException 
C++/CLI  
[SerializableAttribute()]
public ref class RasterException : public LeadtoolsException 

Example

Visual Basic Copy Code
Public Sub Example()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()
 codecs.ThrowExceptionsOnInvalidImages = True

 ' Prompt the user for an image
 Dim dlg As OpenFileDialog = New OpenFileDialog()
 dlg.Filter = "All Files|*.*"
 If dlg.ShowDialog() = DialogResult.OK Then
    ' Try to load this image
    Try
       Dim img As RasterImage = codecs.Load(dlg.FileName)
       MessageBox.Show(String.Format("Image in file {0} is loaded", dlg.FileName))
       img.Dispose()
    Catch ex As RasterException
       ' See if LEADTOOLS could not recognize this image format
       If ex.Code = RasterExceptionCode.FileFormat Then
          MessageBox.Show(String.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.FileName))
       Else
          ' Other LEADTOOLS error (file might be corrupted, read error, etc)
          MessageBox.Show(String.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.FileName, Environment.NewLine, ex.Code, ex.Message))
       End If
    Catch ex As Exception
       ' Other errors
       MessageBox.Show(String.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message))
    End Try
 End If

 ' Clean up
 RasterCodecs.Shutdown()
      End Sub
C# Copy Code
public void Example() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   // Prompt the user for an image 
   OpenFileDialog dlg = new OpenFileDialog(); 
   dlg.Filter = "All Files|*.*"; 
   if(dlg.ShowDialog() == DialogResult.OK) 
   { 
      // Try to load this image 
      try 
      { 
         RasterImage img = codecs.Load(dlg.FileName); 
         MessageBox.Show(string.Format("Image in file {0} is loaded", dlg.FileName)); 
         img.Dispose(); 
      } 
      catch(RasterException ex) 
      { 
         // See if LEADTOOLS could not recognize this image format 
         if(ex.Code == RasterExceptionCode.FileFormat) 
            MessageBox.Show(string.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.FileName)); 
         else 
         { 
            // Other LEADTOOLS error (file might be corrupted, read error, etc) 
            MessageBox.Show(string.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.FileName, Environment.NewLine, ex.Code, ex.Message)); 
         } 
      } 
      catch(Exception ex) 
      { 
         // Other errors 
         MessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message)); 
      } 
   } 
 
   // Clean up 
   RasterCodecs.Shutdown(); 
}

Remarks

The RasterException class defines a Code property that you can examine to determine what caused the error.

Default messages are implemented for each Code, you can get the message through the GetCodeMessage method.

Inheritance Hierarchy

System.Object
   System.Exception
      Leadtools.LeadtoolsException
         Leadtools.RasterException

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also