←Select platform

BarcodeReaderErrorMode Enumeration

Summary
Indicates how to handle errors when reading barcodes.
Syntax
C#
Objective-C
C++/CLI
Java
Python
[SerializableAttribute()] 
public enum BarcodeReaderErrorMode   
typedef NS_ENUM(NSInteger, LTBarcodeReaderErrorMode) { 
 LTBarcodeReaderErrorModeDefault,  
 LTBarcodeReaderErrorModeIgnoreAll 
}; 
public enum BarcodeReaderErrorMode 
[SerializableAttribute()] 
public enum class BarcodeReaderErrorMode   
class BarcodeReaderErrorMode(Enum): 
   Default = 0 
   IgnoreAll = 1 
Members
ValueMemberDescription
0Default

Default mode. No errors are ignored and an exception will be thrown immediately if an error occurs at any time.

1IgnoreAll

Ignore all errors. When an error occurs, the exception will be saved and passed to the next BarcodeReader.ReadSymbology event (in the BarcodeReadSymbologyEventArgs.Error member).

Remarks

This BarcodeReaderErrorMode enumeration is used as the type for the BarcodeReader.ErrorMode property and is used to determine how to handle the errors when reading barcodes.

The BarcodeReader object might encounter errors when reading barcodes. By default, when an error is encountered, an exception is thrown, usually of type BarcodeException with the BarcodeException.Code set to one of the BarcodeExceptionCode enumeration members, providing more details regarding the error. This is the default behavior.

Sometimes, this behavior may no be desired, for example:

  • The application is trying to decode barcodes on an "if found and correct" bases. If there were corrupted barcodes, the action is to ignore this and continue. In this case, you can set the error mode to IgnoreAll.

    The application is reading multiple barcodes from an image, and the action is to ignore the corrupted barcodes and return only the valid ones found. In this case, you can set the error mode to IgnoreAll and subscribe to the BarcodeReader.ReadSymbology event to get a notification when an error occurs and save the exception for later use. You can then handle these errors when all barcodes are read and the read method returns.

The LEADTOOLS C# Barcode Demo will change the value of ErrorMode to IgnoreAll and use the BarcodeReader.ReadSymbology event to show the errors encountered in a list box.

Note that when the BarcodeReader does not find any barcodes in the image, no exception is thrown. Instead, BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods will return null (Nothing in VB) or an empty array of BarcodeData instead.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
private List<Exception> myErrors;   // List of errors 
 
public void BarcodeReader_ErrorModeExample() 
{ 
   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)) 
      { 
         myErrors = new List<Exception>(); 
 
         // Disable the errors 
         reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll; 
 
         // Subscribe to the ReadSymbology event 
         reader.ReadSymbology += new EventHandler<BarcodeReadSymbologyEventArgs>(myReader_ReadSymbology); 
         // Read all barcodes in the image 
         reader.ReadBarcodes(image, LeadRect.Empty, 0, null); 
         reader.ReadSymbology -= new EventHandler<BarcodeReadSymbologyEventArgs>(myReader_ReadSymbology); 
 
         // Show the errors 
         if (myErrors.Count > 0) 
         { 
            Console.WriteLine("Errors encountered:"); 
            foreach (Exception error in myErrors) 
            { 
               Console.WriteLine(error.Message); 
            } 
         } 
      } 
   } 
} 
 
private void myReader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e) 
{ 
   // If we encounter an error, save it to our list 
   if (e.Error != null) 
   { 
      myErrors.Add(e.Error); 
   } 
} 
 
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; 
 
 
private List<Exception> myErrors; // List of errors 
 
public void barcodeReaderErrorModeExample() { 
   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); 
 
   myErrors = new ArrayList<Exception>(); 
 
   // Disable the errors 
   reader.setErrorMode(BarcodeReaderErrorMode.IGNORE_ALL); 
 
   // Subscribe to the ReadSymbology event 
   reader.addReadSymbologyListener(myReaderReadSymbology); 
 
   // Read all barcodes in the image 
   reader.readBarcodes(image, LeadRect.getEmpty(), 0, null); 
   reader.removeReadSymbologyListener(myReaderReadSymbology); 
 
   // Show the errors 
   if (myErrors.size() > 0) { 
      System.out.println("Errors encountered:"); 
      for (Exception error : myErrors) { 
         System.out.println(error.getMessage()); 
      } 
   } 
 
   String outputFileName = combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"); 
   codecs.save(image, outputFileName, RasterImageFormat.JPEG, 0); 
 
   assertTrue("Image unsuccessfully saved to " + outputFileName, (new File(outputFileName)).exists()); 
   System.out.printf("Image successfully saved to %s%n", outputFileName); 
} 
 
BarcodeReadSymbologyListener myReaderReadSymbology = new BarcodeReadSymbologyListener() { 
 
   @Override 
   public void onReadSymbologyEvent(BarcodeReadSymbologyEvent arg0) { 
      if (arg0.getError() != null) { 
         myErrors.add(arg0.getError()); 
      } 
   } 
 
}; 
Requirements

Target Platforms

See Also

Reference

Leadtools.Barcode Namespace

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.