The exception that is thrown when a LEADTOOLS error occurs.
[SerializableAttribute()]public class RasterException : LeadtoolsException
<SerializableAttribute()>Public Class RasterExceptionInherits LeadtoolsExceptionImplements System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
public class RasterException extends LeadtoolsException [SerializableAttribute()]public ref class RasterException : public LeadtoolsException, System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
The RasterException class defines a Code property that can be examined to determine what caused the error.
Default messages are implemented for each Code. Get the message by calling the GetCodeMessage method.
using Leadtools;using Leadtools.Codecs;public void Example(){RasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;// Prompt the user for an imageOpenFileDialog dlg = new OpenFileDialog();dlg.Filter = "All Files|*.*";if (dlg.ShowDialog() == DialogResult.OK){// Try to load this imagetry{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 formatif (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 errorsMessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message));}}}
Imports LeadtoolsImports Leadtools.CodecsPublic Sub Example()Dim codecs As RasterCodecs = New RasterCodecs()codecs.ThrowExceptionsOnInvalidImages = True' Prompt the user for an imageDim dlg As OpenFileDialog = New OpenFileDialog()dlg.Filter = "All Files|*.*"If dlg.ShowDialog() = DialogResult.OK Then' Try to load this imageTryDim 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 formatIf ex.Code = RasterExceptionCode.FileFormat ThenMessageBox.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 IfCatch ex As Exception' Other errorsMessageBox.Show(String.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message))End TryEnd IfEnd Sub
c#[Silverlight C# Example]using Leadtools;using Leadtools.Codecs;public void Example(){RasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;// Prompt the user for an imageOpenFileDialog dlg = new OpenFileDialog();dlg.Filter = "All Files|*.*";if (dlg.ShowDialog() == true){// Try to load this imagetry{using (FileStream fs = dlg.File.OpenRead()){RasterImage img = codecs.Load(fs);MessageBox.Show(string.Format("Image in file {0} is loaded", dlg.File.FullName));img.Dispose();}}catch (RasterException ex){// See if LEADTOOLS could not recognize this image formatif (ex.Code == RasterExceptionCode.FileFormat)MessageBox.Show(string.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.File.FullName));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.File.FullName, Environment.NewLine, ex.Code, ex.Message));}}catch (Exception ex){// Other errorsMessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", dlg.File.FullName, Environment.NewLine, ex.Message));}}}vb[Silverlight VB Example]Imports LeadtoolsImports Leadtools.CodecsPublic Sub Example()Dim codecs As RasterCodecs = New RasterCodecs()codecs.ThrowExceptionsOnInvalidImages = True' Prompt the user for an imageDim dlg As OpenFileDialog = New OpenFileDialog()dlg.Filter = "All Files|*.*"If dlg.ShowDialog() = True Then' Try to load this imageTryUsing fs As FileStream = dlg.File.OpenRead()Dim img As RasterImage = codecs.Load(fs)MessageBox.Show(String.Format("Image in file {0} is loaded", dlg.File.FullName))img.Dispose()End UsingCatch ex As RasterException' See if LEADTOOLS could not recognize this image formatIf ex.Code = RasterExceptionCode.FileFormat ThenMessageBox.Show(String.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.File.FullName))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.File.FullName, Environment.NewLine, ex.Code, ex.Message))End IfCatch ex As Exception' Other errorsMessageBox.Show(String.Format("Could not load the file {0}.{1}{2}", dlg.File.FullName, Environment.NewLine, ex.Message))End TryEnd IfEnd Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
