Represents the exception that is thrown when a runtime error occurs inside the IOcrEngine
[SerializableAttribute()]public class OcrException : Exception
<SerializableAttribute()>Public Class OcrExceptionInherits System.ExceptionImplements System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
public class OcrException extends RuntimeException [SerializableAttribute()]public ref class OcrException : public System.Exception, System.Runtime.InteropServices._Exception, System.Runtime.Serialization.ISerializable
When a runtime error occurs in the IOcrEngine, an exception of type OcrException is thrown with the engine-specific error code set in the Code member. This error code is engine-specific but a short description can be obtained using the Message property of this class or by using the IOcrEngine.GetErrorCodeString method.
Logic errors such as invalid parameters to methods or invalid operations throw standard .NET exceptions (in this case, ArgumentException and InvalidOperationException respectively Errors caused by loading invalid image files using IOcrEngine.RasterCodecsInstance will throw exceptions of type RasterException. Errors for missing features (support locked) will throw OcrSupportLockedException exceptions. Any other runtime error in the engine will throw an OcrException.
This example shows how to trap various types of exceptions during OCR operations.
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms.Ocr;using Leadtools.Forms.DocumentWriters;public void OcrExceptionExample(){try{// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf");// Create a page// Create an OCR documentusing (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()){// Add a page to the documentIOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null);// Recognize the page// Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will// check and automatically auto-zones the pageocrPage.Recognize(null);// Save the document we have as PDFocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null);}// Shutdown the engine// Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown();}}catch (OcrSupportLockedException ex){Console.WriteLine("Support is locked. You need to unlock '{0}' in this engine to use this feature", ex.SupportType);}catch (OcrException ex){Console.WriteLine("OCR Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message);}catch (RasterException ex){Console.WriteLine("LEADTOOLS Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message);}catch (Exception ex){Console.WriteLine("System Error\nMessage:{0}", ex.Message);}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Forms.OcrImports Leadtools.Forms.DocumentWritersPublic Sub OcrExceptionExample()Try' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf")' Create a page' Create an OCR documentUsing ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()' Add a page to the documentDim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)' Recognize the page' Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will' check and automatically auto-zones the pageocrPage.Recognize(Nothing)' Save the document we have as PDFocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing)End Using' Shutdown the engine' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End UsingCatch ex As OcrSupportLockedExceptionConsole.WriteLine("Support is locked. You need to unlock '{0}' in this engine to use this feature", ex.SupportType)Catch ex As OcrExceptionConsole.WriteLine("OCR Error" & vbLf & "Code: {0}" & vbLf & "Message:{1}", ex.Code, ex.Message)Catch ex As RasterExceptionConsole.WriteLine("LEADTOOLS Error" & vbLf & "Code: {0}" & vbLf & "Message:{1}", ex.Code, ex.Message)Catch ex As ExceptionConsole.WriteLine("System Error" & vbLf & "Message:{0}", ex.Message)End TryEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"End Class
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
