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



The exception that is thrown when a WIA error occurs.

Syntax

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

Example

Visual BasicCopy Code
<Test> _
Public Sub WiaExceptionExample(ByVal parent As IWin32Window)
   Dim wiaSession As WiaSession = Nothing
   Try
      If (Not WiaSession.IsAvailable(WiaVersion.Version1)) Then
         MessageBox.Show("WIA version 1.0 not installed.")
         Return
      End If

      ' initialize a new WIA wiaSession
      wiaSession = New WiaSession()
      wiaSession.Startup(WiaVersion.Version1)

      Dim res As DialogResult = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault)
      If res <> DialogResult.OK Then
         MessageBox.Show("Error selecting WIA device.")
         wiaSession.Shutdown()
         Return
      End If

      ' acquire a page, if paper jam, allow the user to retry
      Dim done As Boolean = False
      Do While Not done
         Try
            AddHandler wiaSession.AcquireEvent, AddressOf wiaSession_AcquireEvent2

            res = wiaSession.Acquire(parent, Nothing, WiaAcquireFlags.ShowUserInterface Or WiaAcquireFlags.UseCommonUI)
            MessageBox.Show("Success")
            done = True

            RemoveHandler wiaSession.AcquireEvent, AddressOf wiaSession_AcquireEvent2
         Catch ex As WiaException
            If ex.Code = WiaExceptionCode.PaperJam Then
               If MessageBox.Show("Paper jam. Fix and retry?", "WIA", MessageBoxButtons.YesNo) = DialogResult.No Then
                  done = True
               End If
            Else
               ' other error, propagate
               Throw ex
            End If
         End Try
      Loop
   Catch ex As WiaException
      MessageBox.Show(String.Format("WIA error:{0}Code: {1}{0}Message: {2}", Environment.NewLine, ex.Code, ex.Message))
   Catch ex As Exception
      MessageBox.Show(String.Format("Other error: Message:{0}", ex.Message))
   Finally
      If Not wiaSession Is Nothing Then
         wiaSession.Shutdown()
      End If
   End Try
End Sub

Private Sub wiaSession_AcquireEvent2(ByVal sender As Object, ByVal e As WiaAcquireEventArgs)
   Application.DoEvents()

   If Not e.Image Is Nothing Then
      e.Image.Dispose()
   End If

   e.Cancel = False
End Sub
C#Copy Code
public void WiaExceptionExample(IWin32Window parent) 

   WiaSession wiaSession = null; 
 
   try 
   { 
      if (!WiaSession.IsAvailable(WiaVersion.Version1)) 
      { 
         MessageBox.Show("WIA version 1.0 not installed."); 
         return; 
      } 
 
      // initialize a new WIA wiaSession 
      wiaSession = new WiaSession(); 
      wiaSession.Startup(WiaVersion.Version1); 
 
      DialogResult res = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault); 
      if (res != DialogResult.OK) 
      { 
         MessageBox.Show("Error selecting WIA device."); 
         wiaSession.Shutdown(); 
         return; 
      } 
 
      // acquire a page, if paper jam, allow the user to retry 
      bool done = false; 
      while(!done) 
      { 
         try 
         { 
            wiaSession.AcquireEvent += new EventHandler<WiaAcquireEventArgs>(wiaSession_AcquireEvent2); 
 
            res = wiaSession.Acquire(parent, null, WiaAcquireFlags.ShowUserInterface | WiaAcquireFlags.UseCommonUI); 
            MessageBox.Show("Success"); 
            done = true; 
 
            wiaSession.AcquireEvent -= new EventHandler<WiaAcquireEventArgs>(wiaSession_AcquireEvent2); 
         } 
         catch(WiaException ex) 
         { 
            if(ex.Code == WiaExceptionCode.PaperJam) 
            { 
               if(MessageBox.Show("Paper jam.  Fix and retry?", "WIA", MessageBoxButtons.YesNo) == DialogResult.No) 
                  done = true; 
            } 
            else 
            { 
               // other error, propagate 
               throw ex; 
            } 
         } 
      } 
   } 
   catch(WiaException ex) 
   { 
      MessageBox.Show(string.Format("WIA error:{0}Code: {1}{0}Message: {2}", Environment.NewLine, ex.Code, ex.Message)); 
   } 
   catch(Exception ex) 
   { 
      MessageBox.Show(string.Format("Other error: Message:{0}", ex.Message)); 
   } 
   finally 
   { 
      if(wiaSession != null) 
         wiaSession.Shutdown(); 
   } 

 
void wiaSession_AcquireEvent2(object sender, WiaAcquireEventArgs e) 

   Application.DoEvents(); 
 
   if (e.Image != null) 
      e.Image.Dispose(); 
 
   e.Cancel = false; 
}

Remarks

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

Default messages are implemented for each Code. You can, however, modify any message by using the GetCodeMessage and SetCodeMessage methods.

Inheritance Hierarchy

System.Object
   System.Exception
      Leadtools.LeadtoolsException
         Leadtools.Wia.WiaException

Requirements

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

See Also