←Select platform

Error Property

Summary
Any error that may have occurred during the read operation.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public Exception Error { get; } 
@property (nonatomic, strong, readonly, nullable) NSError* error; 
public RuntimeException getError() 
public: 
property Exception^ Error { 
   Exception^ get(); 
} 

Property Value

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).

Remarks

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.

Example
C#
Java
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 engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode reader instance 
   BarcodeReader reader = engine.Reader; 
          
   // Load the image 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Subscribe to the ReadSymbology event 
         reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(reader_ReadSymbology); 
         // Read all barcodes in the image 
         reader.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 read 
      Console.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 errors 
         BarcodeData barcode = e.Data; 
         if (barcode != null) 
         { 
            // Found a barcode, show it 
            Console.WriteLine("  {0} at {1} with data {2}", barcode.Symbology, barcode.Bounds, barcode.Value); 
         } 
         else 
         { 
            Console.WriteLine("  No barcodes found"); 
         } 
      } 
      else 
      { 
         // Show the error 
         Console.WriteLine("Error: {0}", e.Error.Message); 
 
         // Tell the reader top stop reading barcodes 
         e.Status = BarcodeReadSymbologyStatus.Abort; 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.util.*; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
 
import org.junit.*; 
import org.junit.Test; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.*; 
import leadtools.internal.ManualResetEvent; 
 
 
public void barcodeReaderReadSymbologyExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_IMAGES_DIR, "barcode1.tif"); 
 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode reader instance 
   BarcodeReader reader = engine.getReader(); 
 
   // Load the image 
   RasterCodecs codecs = new RasterCodecs(); 
 
   RasterImage image = codecs.load(imageFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1); 
   codecs.save(image, "Result.jpg", RasterImageFormat.JPEG, 0); 
 
   // Subscribe to the ReadSymbology event 
   reader.addReadSymbologyListener(readerReadSymbology); 
 
   // Read all barcodes in the image 
   reader.readBarcodes(image, LeadRect.getEmpty(), 0, null); 
   reader.removeReadSymbologyListener(readerReadSymbology); 
 
   assertTrue("Image unsuccessfully saved", (new File("Result.jpg")).exists()); 
   System.out.printf("Image loaded and saved to %s%n", new File("Result.jpg")); 
} 
 
BarcodeReadSymbologyListener readerReadSymbology = new BarcodeReadSymbologyListener() { 
 
   @Override 
   public void onReadSymbologyEvent(BarcodeReadSymbologyEvent arg0) { 
 
      if (arg0.getOperation() == BarcodeReadSymbologyOperation.PRE_READ) { 
 
         // Before reading, show the symbologies the engine is going to try to read 
         System.out.println("Trying to read the following symbologies:"); 
         BarcodeSymbology[] symbologies = arg0.getSymbologies(); 
 
         for (int i = 0; i < symbologies.length; i++) { 
            System.out.print(symbologies[i]); 
 
            if (i != (symbologies.length - 1)) { 
               System.out.print(", "); 
               System.out.println(arg0.getOptions().getFriendlyName()); 
 
            } else { 
               System.out.println(" "); 
            } 
         } 
      } 
 
      else if (arg0.getOperation() == BarcodeReadSymbologyOperation.POST_READ) { 
 
         if (arg0.getError() == null) { 
 
            // No errors 
            BarcodeData barcode = arg0.getData(); 
 
            if (barcode != null) { 
 
               // Found a barcode, show it 
               System.out.printf("  %1s at %2s with data %3s%n", barcode.getSymbology(), barcode.getBounds(), 
                     barcode.getValue()); 
            } else { 
               System.out.println("  No barcodes found"); 
            } 
         } else { 
            // Show the error 
            System.out.printf("Error: %1s%n", arg0.getError().getMessage()); 
 
            // Tell the reader top stop reading barcodes 
            arg0.setStatus(BarcodeReadSymbologyStatus.ABORT); 
         } 
      } 
   } 
 
}; 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.