public Exception Error { get; }
An Exception object that contains any error that may have occurred during the read operation. Otherwise (no errors occurred), it will be null (Nothing in VB).
If an error occurs during the read operation and Error contains a valid exception object, then depending on the value of BarcodeReader.ErrorMode, the BarcodeReader object may throw this exception after the event handler returns. This is determined as follows:
| Value | Action |
|---|---|
| BarcodeReaderErrorMode.Default |
(Default behavior). The BarcodeReader will throw the error after the event handler returns. You must catch this exception in your application. |
| BarcodeReaderErrorMode.IgnoreAll |
The Exception object is still in Error, but the BarcodeReader will not throw the exception when the event handler returns. It is up to you to decide if and when to throw the exception and how to handle it. The C# and VB Barcode Main Demo shows the errors (if any) in a list after the read operation is completed. |
using Leadtools;using Leadtools.Codecs;using Leadtools.Barcode;using Leadtools.ImageProcessing;public void BarcodeReader_ReadSymbologyExample(){string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");// Create a Barcode engineBarcodeEngine engine = new BarcodeEngine();// Get the Barcode reader instanceBarcodeReader reader = engine.Reader;// Load the imageusing (RasterCodecs codecs = new RasterCodecs()){using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){// Subscribe to the ReadSymbology eventreader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology);// Read all barcodes in the imagereader.ReadBarcodes(image, LeadRect.Empty, 0, null);reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology);}}}private void reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e){if (e.Operation == BarcodeReadSymbologyOperation.PreRead){// Before reading, show the symbologies the engine is going to try to readConsole.WriteLine("Trying to read the following symbologies:");BarcodeSymbology[] symbologies = e.GetSymbologies();for (int i = 0; i < symbologies.Length; i++){Console.Write(symbologies[i]);if (i != (symbologies.Length - 1)){Console.Write(", ");Console.WriteLine(e.Options.FriendlyName);}else{Console.WriteLine();}}}else if (e.Operation == BarcodeReadSymbologyOperation.PostRead){if (e.Error == null){// No errorsBarcodeData barcode = e.Data;if (barcode != null){// Found a barcode, show itConsole.WriteLine(" {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value);}else{Console.WriteLine(" No barcodes found");}}else{// Show the errorConsole.WriteLine("Error: {0}", e.Error.Message);// Tell the reader top stop reading barcodese.Status = BarcodeReadSymbologyStatus.Abort;}}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}