From f09b742ea2fdd27902333b2a64679ee11afea72d Mon Sep 17 00:00:00 2001 From: "christian.brunschen" Date: Sat, 27 Jun 2009 13:22:03 +0000 Subject: [PATCH] * Throw the actual exception objects, rather than pointers to them, i.e.: - replace |throw new FooException()| with |throw FooException()| - replace |catch (FooException *ex)| with |catch (FooExceptio ex)| - update all uses of caught exceptions appropriately: . replace |ex->foo| with |ex.foo| . remove all attempts to delete the caught exception(s) * Add 'const' to the 'char *' declarations for character encoding names git-svn-id: https://zxing.googlecode.com/svn/trunk@1002 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../src/GrayBytesMonochromeBitmapSource.cpp | 2 +- cpp/core/src/MonochromeBitmapSource.cpp | 4 +-- cpp/core/src/common/BitArray.cpp | 2 +- cpp/core/src/common/BitMatrix.cpp | 6 ++-- cpp/core/src/common/BitSource.cpp | 2 +- cpp/core/src/common/BlackPointEstimator.cpp | 2 +- cpp/core/src/common/GridSampler.cpp | 4 +-- cpp/core/src/common/reedsolomon/GF256.cpp | 6 ++-- cpp/core/src/common/reedsolomon/GF256Poly.cpp | 6 ++-- .../common/reedsolomon/ReedSolomonDecoder.cpp | 6 ++-- .../src/qrcode/decoder/BitMatrixParser.cpp | 8 +++--- cpp/core/src/qrcode/decoder/DataBlock.cpp | 4 +-- cpp/core/src/qrcode/decoder/DataMask.cpp | 2 +- .../qrcode/decoder/DecodedBitStreamParser.cpp | 28 +++++++++---------- .../qrcode/decoder/DecodedBitStreamParser.h | 14 +++++----- cpp/core/src/qrcode/decoder/Decoder.cpp | 5 ++-- .../src/qrcode/decoder/ErrorCorrectionLevel.h | 2 +- cpp/core/src/qrcode/decoder/Mode.cpp | 2 +- cpp/core/src/qrcode/decoder/Version.cpp | 4 +-- .../detector/AlignmentPatternFinder.cpp | 2 +- cpp/core/src/qrcode/detector/Detector.cpp | 7 ++--- .../qrcode/detector/FinderPatternFinder.cpp | 2 +- .../src/common/BlackPointEstimatorTest.cpp | 3 +- .../common/reedsolomon/ReedSolomonTest.cpp | 3 +- .../decoder/ErrorCorrectionLevelTest.cpp | 3 +- .../tests/src/qrcode/decoder/ModeTest.cpp | 3 +- .../tests/src/qrcode/decoder/VersionTest.cpp | 3 +- iphone/Classes/Decoder.m | 10 +++---- 28 files changed, 68 insertions(+), 77 deletions(-) diff --git a/cpp/core/src/GrayBytesMonochromeBitmapSource.cpp b/cpp/core/src/GrayBytesMonochromeBitmapSource.cpp index dce0efeda..957b41520 100644 --- a/cpp/core/src/GrayBytesMonochromeBitmapSource.cpp +++ b/cpp/core/src/GrayBytesMonochromeBitmapSource.cpp @@ -33,7 +33,7 @@ size_t GrayBytesMonochromeBitmapSource::getHeight() { unsigned char GrayBytesMonochromeBitmapSource::getPixel(size_t x, size_t y) { if (x >= width_ || y >= height_) { - throw new ReaderException("bitmap coordinate out of bounds"); + throw ReaderException("bitmap coordinate out of bounds"); } size_t index = y * bytesPerRow_ + x; return bytes_[index]; diff --git a/cpp/core/src/MonochromeBitmapSource.cpp b/cpp/core/src/MonochromeBitmapSource.cpp index e46899b4a..d43d03da4 100644 --- a/cpp/core/src/MonochromeBitmapSource.cpp +++ b/cpp/core/src/MonochromeBitmapSource.cpp @@ -95,7 +95,7 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) { } } else if (method == BlackPointEstimationMethod_RowSampling) { if (arg < 0 || arg >= (int)height) { - throw new IllegalArgumentException + throw IllegalArgumentException ("black point estimation argument out of range"); } size_t y = static_cast (arg); @@ -103,7 +103,7 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) { histogram[getPixel(x, y) >> LUMINANCE_SHIFT]++; } } else { - throw new IllegalArgumentException + throw IllegalArgumentException ("unknown black point estimation method"); } diff --git a/cpp/core/src/common/BitArray.cpp b/cpp/core/src/common/BitArray.cpp index 01f1a1b79..0b3a5a6bb 100644 --- a/cpp/core/src/common/BitArray.cpp +++ b/cpp/core/src/common/BitArray.cpp @@ -72,7 +72,7 @@ namespace common { } bool BitArray::isRange(size_t start, size_t end, bool value) { if (end < start) { - throw new IllegalArgumentException("end must be after start"); + throw IllegalArgumentException("end must be after start"); } if (end == start) { return true; diff --git a/cpp/core/src/common/BitMatrix.cpp b/cpp/core/src/common/BitMatrix.cpp index 356e0b301..bef0e59a4 100644 --- a/cpp/core/src/common/BitMatrix.cpp +++ b/cpp/core/src/common/BitMatrix.cpp @@ -73,15 +73,15 @@ namespace common { size_t height, size_t width) { if (topI < 0 || leftJ < 0) { - throw new IllegalArgumentException("topI and leftJ must be nonnegative"); + throw IllegalArgumentException("topI and leftJ must be nonnegative"); } if (height < 1 || width < 1) { - throw new IllegalArgumentException("height and width must be at least 1"); + throw IllegalArgumentException("height and width must be at least 1"); } size_t maxJ = leftJ + width; size_t maxI = topI + height; if (maxI > dimension_ || maxJ > dimension_) { - throw new IllegalArgumentException + throw IllegalArgumentException ("topI + height and leftJ + width must be <= matrix dimension"); } for (size_t j = leftJ; j < maxJ; j++) { diff --git a/cpp/core/src/common/BitSource.cpp b/cpp/core/src/common/BitSource.cpp index 9d54903ef..6a2f2f693 100644 --- a/cpp/core/src/common/BitSource.cpp +++ b/cpp/core/src/common/BitSource.cpp @@ -24,7 +24,7 @@ namespace common { int BitSource::readBits(int numBits) { if (numBits < 0 || numBits > 32) { - throw new IllegalArgumentException("cannot read <1 or >32 bits"); + throw IllegalArgumentException("cannot read <1 or >32 bits"); } int result = 0; diff --git a/cpp/core/src/common/BlackPointEstimator.cpp b/cpp/core/src/common/BlackPointEstimator.cpp index 9b4e1e1f5..655fc89b9 100644 --- a/cpp/core/src/common/BlackPointEstimator.cpp +++ b/cpp/core/src/common/BlackPointEstimator.cpp @@ -70,7 +70,7 @@ namespace common { // for 1D formats, which are relatively lenient. // We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart" if (secondPeak - firstPeak <= numBuckets >> 4) { - throw new IllegalArgumentException + throw IllegalArgumentException ("Too little dynamic range in luminance"); } diff --git a/cpp/core/src/common/GridSampler.cpp b/cpp/core/src/common/GridSampler.cpp index 4fa57fccf..299bfe111 100644 --- a/cpp/core/src/common/GridSampler.cpp +++ b/cpp/core/src/common/GridSampler.cpp @@ -77,7 +77,7 @@ namespace common { if (x < -1 || x > width || y < -1 || y > height) { ostringstream s; s << "Transformed point out of bounds at " << x << "," << y; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } nudged = false; if (x == -1) { @@ -103,7 +103,7 @@ namespace common { if (x < -1 || x > width || y < -1 || y > height) { ostringstream s; s << "Transformed point out of bounds at " << x << "," << y; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } nudged = false; if (x == -1) { diff --git a/cpp/core/src/common/reedsolomon/GF256.cpp b/cpp/core/src/common/reedsolomon/GF256.cpp index edb5c0581..fdf98930a 100644 --- a/cpp/core/src/common/reedsolomon/GF256.cpp +++ b/cpp/core/src/common/reedsolomon/GF256.cpp @@ -75,7 +75,7 @@ namespace reedsolomon { cout << __FUNCTION__ << "\n"; #endif if (degree < 0) { - throw new IllegalArgumentException("Degree must be non-negative"); + throw IllegalArgumentException("Degree must be non-negative"); } if (coefficient == 0) { return zero_; @@ -97,14 +97,14 @@ namespace reedsolomon { int GF256::log(int a) { if (a == 0) { - throw new IllegalArgumentException("Cannot take the logarithm of 0"); + throw IllegalArgumentException("Cannot take the logarithm of 0"); } return log_[a]; } int GF256::inverse(int a) { if (a == 0) { - throw new IllegalArgumentException("Cannot calculate the inverse of 0"); + throw IllegalArgumentException("Cannot calculate the inverse of 0"); } return exp_[255 - log_[a]]; } diff --git a/cpp/core/src/common/reedsolomon/GF256Poly.cpp b/cpp/core/src/common/reedsolomon/GF256Poly.cpp index 8f4201ca6..b9d7dfa6d 100644 --- a/cpp/core/src/common/reedsolomon/GF256Poly.cpp +++ b/cpp/core/src/common/reedsolomon/GF256Poly.cpp @@ -99,7 +99,7 @@ namespace reedsolomon { GF256Poly *GF256Poly::addOrSubtract(GF256Poly *b) { if (&field != &b->field) { - throw new IllegalArgumentException("Fields must be the same"); + throw IllegalArgumentException("Fields must be the same"); } if (isZero()) { return b; @@ -131,7 +131,7 @@ namespace reedsolomon { GF256Poly *GF256Poly::multiply(GF256Poly *b) { if (&field != &b->field) { - throw new IllegalArgumentException("Fields must be the same"); + throw IllegalArgumentException("Fields must be the same"); } if (isZero() || b->isZero()) { return field.getZero(); @@ -172,7 +172,7 @@ namespace reedsolomon { GF256Poly *GF256Poly::multiplyByMonomial(int degree, int coefficient) { if (degree < 0) { - throw new IllegalArgumentException("Degree must be non-negative"); + throw IllegalArgumentException("Degree must be non-negative"); } if (coefficient == 0) { return field.getZero(); diff --git a/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp b/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp index 92c75283a..7fcc8ff10 100644 --- a/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp +++ b/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp @@ -106,7 +106,7 @@ namespace reedsolomon { // Divide rLastLast by rLast, with quotient q and remainder r if (rLast->isZero()) { // Oops, Euclidean algorithm already terminated? - throw new ReedSolomonException("r_{i-1} was zero"); + throw ReedSolomonException("r_{i-1} was zero"); } r = rLastLast; Ref q(field.getZero()); @@ -126,7 +126,7 @@ namespace reedsolomon { int sigmaTildeAtZero = t->getCoefficient(0); if (sigmaTildeAtZero == 0) { - throw new ReedSolomonException("sigmaTilde(0) was zero"); + throw ReedSolomonException("sigmaTilde(0) was zero"); } int inverse = field.inverse(sigmaTildeAtZero); @@ -165,7 +165,7 @@ namespace reedsolomon { } } if (e != numErrors) { - throw new ReedSolomonException + throw ReedSolomonException ("Error locator degree does not match number of roots"); } return result; diff --git a/cpp/core/src/qrcode/decoder/BitMatrixParser.cpp b/cpp/core/src/qrcode/decoder/BitMatrixParser.cpp index ffc84232d..9641de3b1 100644 --- a/cpp/core/src/qrcode/decoder/BitMatrixParser.cpp +++ b/cpp/core/src/qrcode/decoder/BitMatrixParser.cpp @@ -36,7 +36,7 @@ namespace qrcode { bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() { int dimension = bitMatrix->getDimension(); if ((dimension < 21) || (dimension & 0x03) != 1) { - throw new ReaderException("Dimension must be 1 mod 4 and >= 21"); + throw ReaderException("Dimension must be 1 mod 4 and >= 21"); } } @@ -79,7 +79,7 @@ namespace qrcode { if (parsedFormatInfo_ != 0) { return parsedFormatInfo_; } - throw new ReaderException("Could not decode format information"); + throw ReaderException("Could not decode format information"); } Version *BitMatrixParser::readVersion() { @@ -121,7 +121,7 @@ namespace qrcode { if (parsedVersion_ != 0) { return parsedVersion_; } - throw new ReaderException("Could not decode version"); + throw ReaderException("Could not decode version"); } ArrayRef BitMatrixParser::readCodewords() { @@ -177,7 +177,7 @@ namespace qrcode { readingUp = !readingUp; // switch directions } if (resultOffset != version->getTotalCodewords()) { - throw new ReaderException("Did not read all codewords"); + throw ReaderException("Did not read all codewords"); } return result; } diff --git a/cpp/core/src/qrcode/decoder/DataBlock.cpp b/cpp/core/src/qrcode/decoder/DataBlock.cpp index 0855cdf68..0a0349091 100644 --- a/cpp/core/src/qrcode/decoder/DataBlock.cpp +++ b/cpp/core/src/qrcode/decoder/DataBlock.cpp @@ -67,7 +67,7 @@ namespace qrcode { break; } if (numCodewords != shorterBlocksTotalCodewords + 1) { - throw new IllegalArgumentException("Data block sizes differ by more than 1"); + throw IllegalArgumentException("Data block sizes differ by more than 1"); } longerBlocksStartAt--; } @@ -96,7 +96,7 @@ namespace qrcode { } if ((size_t) rawCodewordsOffset != rawCodewords.size()) { - throw new IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); + throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); } return result; diff --git a/cpp/core/src/qrcode/decoder/DataMask.cpp b/cpp/core/src/qrcode/decoder/DataMask.cpp index ae9de9879..6531d6e11 100644 --- a/cpp/core/src/qrcode/decoder/DataMask.cpp +++ b/cpp/core/src/qrcode/decoder/DataMask.cpp @@ -30,7 +30,7 @@ namespace qrcode { DataMask &DataMask::forReference(int reference) { if (reference < 0 || reference > 7) { - throw new IllegalArgumentException("reference must be between 0 and 7"); + throw IllegalArgumentException("reference must be between 0 and 7"); } return *DATA_MASKS[reference]; } diff --git a/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.cpp b/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.cpp index 50527fe7e..5a2751624 100644 --- a/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.cpp +++ b/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.cpp @@ -27,18 +27,18 @@ namespace qrcode { using namespace common; using namespace std; - char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = { + const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':' }; - char *DecodedBitStreamParser::ASCII = "ASCII"; - char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1"; - char *DecodedBitStreamParser::UTF8 = "UTF-8"; - char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS"; - char *DecodedBitStreamParser::EUC_JP = "EUC-JP"; + const char *DecodedBitStreamParser::ASCII = "ASCII"; + const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1"; + const char *DecodedBitStreamParser::UTF8 = "UTF-8"; + const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS"; + const char *DecodedBitStreamParser::EUC_JP = "EUC-JP"; void DecodedBitStreamParser::append(ostream &ost, unsigned char *bufIn, @@ -59,7 +59,7 @@ namespace qrcode { while (nFrom > 0) { size_t oneway = iconv(cd, &fromPtr, &nFrom, &toPtr, &nTo); if (oneway == (size_t)(-1)) { - throw new ReaderException("error converting characters"); + throw ReaderException("error converting characters"); } } iconv_close(cd); @@ -106,7 +106,7 @@ namespace qrcode { if (count << 3 > bits->available()) { ostringstream s; s << "Count too large: " << count; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } for (int i = 0; i < count; i++) { readBytes[i] = (unsigned char) bits->readBits(8); @@ -116,7 +116,7 @@ namespace qrcode { // upon decoding. I have seen ISO-8859-1 used as well as // Shift_JIS -- without anything like an ECI designator to // give a hint. - char *encoding = guessEncoding(readBytes, nBytes); + const char *encoding = guessEncoding(readBytes, nBytes); append(result, readBytes, nBytes, encoding); } @@ -133,7 +133,7 @@ namespace qrcode { if (threeDigitsBits >= 1000) { ostringstream s; s << "Illegal value for 3-digit unit: " << threeDigitsBits; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits / 100]; bytes[i++] = ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]; @@ -146,7 +146,7 @@ namespace qrcode { if (twoDigitsBits >= 100) { ostringstream s; s << "Illegal value for 2-digit unit: " << twoDigitsBits; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits / 10]; bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits % 10]; @@ -156,7 +156,7 @@ namespace qrcode { if (digitBits >= 10) { ostringstream s; s << "Illegal value for digit unit: " << digitBits; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } bytes[i++] = ALPHANUMERIC_CHARS[digitBits]; } @@ -182,7 +182,7 @@ namespace qrcode { append(result, bytes, nBytes, ASCII); } - char * + const char * DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) { // Does it start with the UTF-8 byte order mark? then guess it's UTF-8 if (length > 3 && bytes[0] == (unsigned char) 0xEF && @@ -262,7 +262,7 @@ namespace qrcode { } else if (mode == &Mode::KANJI) { decodeKanjiSegment(bits, result, count); } else { - throw new ReaderException("Unsupported mode indicator"); + throw ReaderException("Unsupported mode indicator"); } } } while (mode != &Mode::TERMINATOR); diff --git a/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.h b/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.h index 794d8e04d..8c2cb218e 100644 --- a/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.h +++ b/cpp/core/src/qrcode/decoder/DecodedBitStreamParser.h @@ -38,13 +38,13 @@ namespace qrcode { class DecodedBitStreamParser { private: - static char ALPHANUMERIC_CHARS[]; + static const char ALPHANUMERIC_CHARS[]; - static char *ASCII; - static char *ISO88591; - static char *UTF8; - static char *SHIFT_JIS; - static char *EUC_JP; + static const char *ASCII; + static const char *ISO88591; + static const char *UTF8; + static const char *SHIFT_JIS; + static const char *EUC_JP; static void decodeKanjiSegment(Ref bits, ostringstream &result, @@ -58,7 +58,7 @@ namespace qrcode { static void decodeNumericSegment(Ref bits, ostringstream &result, int count); - static char *guessEncoding(unsigned char *bytes, int length); + static const char *guessEncoding(unsigned char *bytes, int length); static void append(ostream &ost, unsigned char *bufIn, size_t nIn, const char *src); diff --git a/cpp/core/src/qrcode/decoder/Decoder.cpp b/cpp/core/src/qrcode/decoder/Decoder.cpp index d208e5d4c..4e16d964f 100644 --- a/cpp/core/src/qrcode/decoder/Decoder.cpp +++ b/cpp/core/src/qrcode/decoder/Decoder.cpp @@ -45,9 +45,8 @@ namespace qrcode { try { rsDecoder_.decode(codewordInts, numECCodewords); } - catch (ReedSolomonException *ex) { - ReaderException *rex = new ReaderException(ex->what()); - delete ex; + catch (ReedSolomonException ex) { + ReaderException rex(ex.what()); throw rex; } diff --git a/cpp/core/src/qrcode/decoder/ErrorCorrectionLevel.h b/cpp/core/src/qrcode/decoder/ErrorCorrectionLevel.h index 6a5dba5e7..1185116c4 100644 --- a/cpp/core/src/qrcode/decoder/ErrorCorrectionLevel.h +++ b/cpp/core/src/qrcode/decoder/ErrorCorrectionLevel.h @@ -41,7 +41,7 @@ namespace qrcode { int ordinal() { return ordinal_; } static ErrorCorrectionLevel& forBits(int bits) { if (bits < 0 || bits >= N_LEVELS) { - throw new ReaderException("Ellegal error correction level bits"); + throw ReaderException("Ellegal error correction level bits"); } return *FOR_BITS[bits]; } diff --git a/cpp/core/src/qrcode/decoder/Mode.cpp b/cpp/core/src/qrcode/decoder/Mode.cpp index 30dd3170c..3d6c5fcb2 100644 --- a/cpp/core/src/qrcode/decoder/Mode.cpp +++ b/cpp/core/src/qrcode/decoder/Mode.cpp @@ -52,7 +52,7 @@ namespace qrcode { default: ostringstream s; s << "Illegal mode bits: " << bits; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } } diff --git a/cpp/core/src/qrcode/decoder/Version.cpp b/cpp/core/src/qrcode/decoder/Version.cpp index 15bf80ccc..8d772e158 100644 --- a/cpp/core/src/qrcode/decoder/Version.cpp +++ b/cpp/core/src/qrcode/decoder/Version.cpp @@ -63,14 +63,14 @@ namespace qrcode { Version *Version::getProvisionalVersionForDimension(int dimension) { if (dimension %4 != 1) { - throw new ReaderException("Dimension must be 1 mod 4"); + throw ReaderException("Dimension must be 1 mod 4"); } return Version::getVersionForNumber((dimension - 17) >> 2); } Version *Version::getVersionForNumber(int versionNumber) { if (versionNumber < 1 || versionNumber > 40) { - throw new ReaderException("versionNumber must be between 1 and 40"); + throw ReaderException("versionNumber must be between 1 and 40"); } N_VERSIONS; return VERSIONS[versionNumber - 1]; diff --git a/cpp/core/src/qrcode/detector/AlignmentPatternFinder.cpp b/cpp/core/src/qrcode/detector/AlignmentPatternFinder.cpp index 1ee09f3b1..48bbf4585 100644 --- a/cpp/core/src/qrcode/detector/AlignmentPatternFinder.cpp +++ b/cpp/core/src/qrcode/detector/AlignmentPatternFinder.cpp @@ -211,7 +211,7 @@ namespace qrcode { return center; } - throw new ReaderException("Could not find alignment pattern"); + throw ReaderException("Could not find alignment pattern"); } } diff --git a/cpp/core/src/qrcode/detector/Detector.cpp b/cpp/core/src/qrcode/detector/Detector.cpp index 7ed6b3a5a..e73ce860c 100644 --- a/cpp/core/src/qrcode/detector/Detector.cpp +++ b/cpp/core/src/qrcode/detector/Detector.cpp @@ -86,13 +86,12 @@ namespace qrcode { estAlignmentY, (float) i); break; - } catch (ReaderException *re) { + } catch (ReaderException re) { // try next round - delete re; } } if (alignmentPattern == 0) { - throw new ReaderException("Could not find alignment pattern"); + throw ReaderException("Could not find alignment pattern"); } } @@ -173,7 +172,7 @@ namespace qrcode { case 3: ostringstream s; s << "Bad dimension: " << dimension; - throw new ReaderException(s.str().c_str()); + throw ReaderException(s.str().c_str()); } return dimension; } diff --git a/cpp/core/src/qrcode/detector/FinderPatternFinder.cpp b/cpp/core/src/qrcode/detector/FinderPatternFinder.cpp index 3c120dbdf..5604c5bea 100644 --- a/cpp/core/src/qrcode/detector/FinderPatternFinder.cpp +++ b/cpp/core/src/qrcode/detector/FinderPatternFinder.cpp @@ -318,7 +318,7 @@ namespace qrcode { if (size < 3) { // Couldn't find enough finder patterns - throw new ReaderException("Could not find three finder patterns"); + throw ReaderException("Could not find three finder patterns"); } if (size == 3) { diff --git a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp index 350b17a5c..a49df7c6c 100644 --- a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp +++ b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp @@ -41,9 +41,8 @@ namespace common { valarray histogram(histogramRaw, 16); BlackPointEstimator::estimate(histogram); CPPUNIT_FAIL("Should have thrown an exception"); - } catch (IllegalArgumentException* ie) { + } catch (IllegalArgumentException ie) { // good - delete ie; } } } diff --git a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp index 2582da632..a57cade7f 100644 --- a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp +++ b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp @@ -97,9 +97,8 @@ namespace reedsolomon { checkQRRSDecode(received); cout << "expected exception!\n"; CPPUNIT_FAIL("should not happen!"); - } catch (ReedSolomonException *e) { + } catch (ReedSolomonException e) { // expected - delete e; } catch (...) { CPPUNIT_FAIL("unexpected exception!"); } diff --git a/cpp/core/tests/src/qrcode/decoder/ErrorCorrectionLevelTest.cpp b/cpp/core/tests/src/qrcode/decoder/ErrorCorrectionLevelTest.cpp index 7af8a8a79..f5e748665 100644 --- a/cpp/core/tests/src/qrcode/decoder/ErrorCorrectionLevelTest.cpp +++ b/cpp/core/tests/src/qrcode/decoder/ErrorCorrectionLevelTest.cpp @@ -40,9 +40,8 @@ namespace qrcode { ErrorCorrectionLevel::forBits(4); CPPUNIT_FAIL("should have thrown an exception"); } - catch (ReaderException *ex) { + catch (ReaderException ex) { // expected - delete ex; } } } diff --git a/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp b/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp index 0a5be6608..24990b771 100644 --- a/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp +++ b/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp @@ -36,9 +36,8 @@ namespace qrcode { Mode::forBits(0x10); CPPUNIT_FAIL("should have thrown an exception"); } - catch (ReaderException *ex) { + catch (ReaderException ex) { // expected - delete ex; } } diff --git a/cpp/core/tests/src/qrcode/decoder/VersionTest.cpp b/cpp/core/tests/src/qrcode/decoder/VersionTest.cpp index 2b5a46f14..35427db5c 100644 --- a/cpp/core/tests/src/qrcode/decoder/VersionTest.cpp +++ b/cpp/core/tests/src/qrcode/decoder/VersionTest.cpp @@ -56,9 +56,8 @@ namespace qrcode { try { Version::getVersionForNumber(0); CPPUNIT_FAIL("Should have thrown an exception"); - } catch (ReaderException *re) { + } catch (ReaderException re) { // good - delete re; } for (int i = 1; i <= 40; i++) { checkVersion(Version::getVersionForNumber(i), i, 4*i + 17); diff --git a/iphone/Classes/Decoder.m b/iphone/Classes/Decoder.m index 0cac0026f..be43ef017 100644 --- a/iphone/Classes/Decoder.m +++ b/iphone/Classes/Decoder.m @@ -180,14 +180,12 @@ using namespace qrcode; decoderResult = [TwoDDecoderResult resultWithText:resultString points:points]; - } catch (ReaderException *rex) { + } catch (ReaderException rex) { NSLog(@"failed to decode, caught ReaderException '%s'", - rex->what()); - delete rex; - } catch (IllegalArgumentException *iex) { + rex.what()); + } catch (IllegalArgumentException iex) { NSLog(@"failed to decode, caught IllegalArgumentException '%s'", - iex->what()); - delete iex; + iex.what()); } catch (...) { NSLog(@"Caught unknown exception!"); }