The exception that is thrown when a TWAIN error occurs.
[SerializableAttribute()]public class TwainException : Leadtools.LeadtoolsException, System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
<SerializableAttribute()>Public Class TwainExceptionInherits Leadtools.LeadtoolsExceptionImplements System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
[SerializableAttribute()]public ref class TwainException : public Leadtools.LeadtoolsException, System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
The TwainException 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 through the GetCodeMessage and SetCodeMessage methods.
Imports LeadtoolsImports Leadtools.TwainPublic Sub _twainSession_AcquirePage(ByVal sender As Object, ByVal e As TwainAcquirePageEventArgs)Application.DoEvents()If Not e.Image Is Nothing Thene.Image.Dispose()End Ife.Cancel = FalseEnd SubPublic Sub TwainExceptionExample(ByVal parent As IntPtr)Dim session As TwainSession = NothingTry' initialize a new TWAIN sessionsession = New TwainSession()session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)AddHandler session.AcquirePage, AddressOf _twainSession_AcquirePage' acquire a page, if paper jam, allow the user to retryDim done As Boolean = FalseDo While Not doneTryDim res As DialogResult = session.Acquire(TwainUserInterfaceFlags.Modal Or TwainUserInterfaceFlags.Show)MessageBox.Show("Success")done = TrueCatch ex As TwainExceptionIf ex.Code = TwainExceptionCode.PaperJam ThenIf MessageBox.Show("Paper jam. Fix and retry?", "TWAIN", MessageBoxButtons.YesNo) = DialogResult.No Thendone = TrueEnd IfElse' other error, propagateThrow exEnd IfEnd TryLoopCatch ex As TwainExceptionMessageBox.Show(String.Format("Twain error:{0}Code: {1}{0}Message: {2}", Environment.NewLine, ex.Code, ex.Message))Catch ex As ExceptionMessageBox.Show(String.Format("Other error: Message:{0}", ex.Message))FinallyIf Not session Is Nothing Thensession.Shutdown()End IfEnd TryEnd Sub
using Leadtools;using Leadtools.Twain;public void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e){Application.DoEvents();if(e.Image != null)e.Image.Dispose();e.Cancel = false;}public void TwainExceptionExample(IntPtr parent){TwainSession session = null;try{// initialize a new TWAIN sessionsession = new TwainSession();session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);session.AcquirePage += new EventHandler<TwainAcquirePageEventArgs>(_twainSession_AcquirePage);// acquire a page, if paper jam, allow the user to retrybool done = false;while(!done){try{DialogResult res = session.Acquire(TwainUserInterfaceFlags.Modal | TwainUserInterfaceFlags.Show);MessageBox.Show("Success");done = true;}catch(TwainException ex){if(ex.Code == TwainExceptionCode.PaperJam){if(MessageBox.Show("Paper jam. Fix and retry?", "TWAIN", MessageBoxButtons.YesNo) == DialogResult.No)done = true;}else{// other error, propagatethrow ex;}}}}catch(TwainException ex){MessageBox.Show(string.Format("Twain 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(session != null)session.Shutdown();}}
|
Products |
Support |
Feedback: TwainException Class - Leadtools.Twain |
Introduction |
Help Version 19.0.2017.3.22
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.