Korean translation from Chang Hyun Park
[zxing.git] / csharp / ReaderException.cs
1 /*\r
2 * Copyright 2007 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 using System;\r
17 namespace com.google.zxing\r
18 {\r
19         \r
20         /// <summary> The general exception class throw when something goes wrong during decoding of a barcode.\r
21         /// This includes, but is not limited to, failing checksums / error correction algorithms, being\r
22         /// unable to locate finder timing patterns, and so on.\r
23         /// \r
24         /// </summary>\r
25         /// <author>  Sean Owen\r
26         /// </author>\r
27         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
28         /// </author>\r
29 \r
30         [Serializable]\r
31         public sealed class ReaderException:System.Exception\r
32         {\r
33                 public static ReaderException Instance\r
34                 {\r
35                         get\r
36                         {\r
37                                 //    Exception e = new Exception();\r
38                                 //    // Take the stack frame before this one.\r
39                                 //    StackTraceElement stack = e.getStackTrace()[1];\r
40                                 //    String key = stack.getClassName() + "." + stack.getMethodName() + "(), line " +\r
41                                 //        stack.getLineNumber();\r
42                                 //    if (throwers.containsKey(key)) {\r
43                                 //      Integer value = throwers.get(key);\r
44                                 //      value++;\r
45                                 //      throwers.put(key, value);\r
46                                 //    } else {\r
47                                 //      throwers.put(key, 1);\r
48                                 //    }\r
49                                 //    exceptionCount++;\r
50                                 \r
51                                 return instance;\r
52                         }\r
53                         \r
54                 }\r
55                 \r
56                 // TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before\r
57                 // rejecting it. This involves a lot of overhead and memory allocation, and affects both performance\r
58                 // and latency on continuous scan clients. In the future, we should change all the decoders not to\r
59                 // throw exceptions for routine events, like not finding a barcode on a given row. Instead, we\r
60                 // should return error codes back to the callers, and simply delete this class. In the mean time, I\r
61                 // have altered this class to be as lightweight as possible, by ignoring the exception string, and\r
62                 // by disabling the generation of stack traces, which is especially time consuming. These are just\r
63                 // temporary measures, pending the big cleanup.\r
64                 \r
65                 //UPGRADE_NOTE: Final was removed from the declaration of 'instance '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
66                 private static readonly ReaderException instance = new ReaderException();\r
67                 \r
68                 // EXCEPTION TRACKING SUPPORT\r
69                 // Identifies who is throwing exceptions and how often. To use:\r
70                 //\r
71                 // 1. Uncomment these lines and the code below which uses them.\r
72                 // 2. Uncomment the two corresponding lines in j2se/CommandLineRunner.decode()\r
73                 // 3. Change core to build as Java 1.5 temporarily\r
74                 //  private static int exceptionCount = 0;\r
75                 //  private static Map<String,Integer> throwers = new HashMap<String,Integer>(32);\r
76                 \r
77                 private ReaderException()\r
78                 {\r
79                         // do nothing\r
80                 }\r
81                 \r
82                 //  public static int getExceptionCountAndReset() {\r
83                 //    int temp = exceptionCount;\r
84                 //    exceptionCount = 0;\r
85                 //    return temp;\r
86                 //  }\r
87                 //\r
88                 //  public static String getThrowersAndReset() {\r
89                 //    StringBuilder builder = new StringBuilder(1024);\r
90                 //    Object[] keys = throwers.keySet().toArray();\r
91                 //    for (int x = 0; x < keys.length; x++) {\r
92                 //      String key = (String) keys[x];\r
93                 //      Integer value = throwers.get(key);\r
94                 //      builder.append(key);\r
95                 //      builder.append(": ");\r
96                 //      builder.append(value);\r
97                 //      builder.append("\n");\r
98                 //    }\r
99                 //    throwers.clear();\r
100                 //    return builder.toString();\r
101                 //  }\r
102                 \r
103                 // Prevent stack traces from being taken\r
104                 // srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden?\r
105                 // This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow.\r
106                 //UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"\r
107                 //UPGRADE_NOTE: The equivalent of method 'java.lang.Throwable.fillInStackTrace' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"\r
108                 public System.Exception fillInStackTrace()\r
109                 {\r
110                         return null;\r
111                 }\r
112         }\r
113 }