You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReaderException.cs 2.9 kB

10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2007 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. using System;
  17. namespace ZXing
  18. {
  19. /// <summary>
  20. /// The general exception class throw when something goes wrong during decoding of a barcode.
  21. /// This includes, but is not limited to, failing checksums / error correction algorithms, being
  22. /// unable to locate finder timing patterns, and so on.
  23. /// </summary>
  24. /// <author>Sean Owen</author>
  25. [Serializable]
  26. public class ReaderException : Exception
  27. {
  28. /// <summary>
  29. /// Gets the instance.
  30. /// </summary>
  31. public static ReaderException Instance
  32. {
  33. get
  34. {
  35. return instance;
  36. }
  37. }
  38. // TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before
  39. // rejecting it. This involves a lot of overhead and memory allocation, and affects both performance
  40. // and latency on continuous scan clients. In the future, we should change all the decoders not to
  41. // throw exceptions for routine events, like not finding a barcode on a given row. Instead, we
  42. // should return error codes back to the callers, and simply delete this class. In the mean time, I
  43. // have altered this class to be as lightweight as possible, by ignoring the exception string, and
  44. // by disabling the generation of stack traces, which is especially time consuming. These are just
  45. // temporary measures, pending the big cleanup.
  46. //UPGRADE_NOTE: Final was removed from the declaration of 'instance '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
  47. private static readonly ReaderException instance = new ReaderException();
  48. // EXCEPTION TRACKING SUPPORT
  49. // Identifies who is throwing exceptions and how often. To use:
  50. //
  51. // 1. Uncomment these lines and the code below which uses them.
  52. // 2. Uncomment the two corresponding lines in j2se/CommandLineRunner.decode()
  53. // 3. Change core to build as Java 1.5 temporarily
  54. // private static int exceptionCount = 0;
  55. // private static Map<String,Integer> throwers = new HashMap<String,Integer>(32);
  56. /// <summary>
  57. /// Initializes a new instance of the <see cref="ReaderException"/> class.
  58. /// </summary>
  59. protected ReaderException()
  60. {
  61. // do nothing
  62. }
  63. }
  64. }