* 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
This commit is contained in:
christian.brunschen 2009-06-27 13:22:03 +00:00
parent cca4b72bfa
commit f09b742ea2
28 changed files with 68 additions and 77 deletions

View file

@ -33,7 +33,7 @@ size_t GrayBytesMonochromeBitmapSource::getHeight() {
unsigned char GrayBytesMonochromeBitmapSource::getPixel(size_t x, size_t y) { unsigned char GrayBytesMonochromeBitmapSource::getPixel(size_t x, size_t y) {
if (x >= width_ || y >= height_) { 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; size_t index = y * bytesPerRow_ + x;
return bytes_[index]; return bytes_[index];

View file

@ -95,7 +95,7 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) {
} }
} else if (method == BlackPointEstimationMethod_RowSampling) { } else if (method == BlackPointEstimationMethod_RowSampling) {
if (arg < 0 || arg >= (int)height) { if (arg < 0 || arg >= (int)height) {
throw new IllegalArgumentException throw IllegalArgumentException
("black point estimation argument out of range"); ("black point estimation argument out of range");
} }
size_t y = static_cast<size_t> (arg); size_t y = static_cast<size_t> (arg);
@ -103,7 +103,7 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) {
histogram[getPixel(x, y) >> LUMINANCE_SHIFT]++; histogram[getPixel(x, y) >> LUMINANCE_SHIFT]++;
} }
} else { } else {
throw new IllegalArgumentException throw IllegalArgumentException
("unknown black point estimation method"); ("unknown black point estimation method");
} }

View file

@ -72,7 +72,7 @@ namespace common {
} }
bool BitArray::isRange(size_t start, size_t end, bool value) { bool BitArray::isRange(size_t start, size_t end, bool value) {
if (end < start) { if (end < start) {
throw new IllegalArgumentException("end must be after start"); throw IllegalArgumentException("end must be after start");
} }
if (end == start) { if (end == start) {
return true; return true;

View file

@ -73,15 +73,15 @@ namespace common {
size_t height, size_t height,
size_t width) { size_t width) {
if (topI < 0 || leftJ < 0) { 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) { 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 maxJ = leftJ + width;
size_t maxI = topI + height; size_t maxI = topI + height;
if (maxI > dimension_ || maxJ > dimension_) { if (maxI > dimension_ || maxJ > dimension_) {
throw new IllegalArgumentException throw IllegalArgumentException
("topI + height and leftJ + width must be <= matrix dimension"); ("topI + height and leftJ + width must be <= matrix dimension");
} }
for (size_t j = leftJ; j < maxJ; j++) { for (size_t j = leftJ; j < maxJ; j++) {

View file

@ -24,7 +24,7 @@
namespace common { namespace common {
int BitSource::readBits(int numBits) { int BitSource::readBits(int numBits) {
if (numBits < 0 || numBits > 32) { 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; int result = 0;

View file

@ -70,7 +70,7 @@ namespace common {
// for 1D formats, which are relatively lenient. // for 1D formats, which are relatively lenient.
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart" // We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
if (secondPeak - firstPeak <= numBuckets >> 4) { if (secondPeak - firstPeak <= numBuckets >> 4) {
throw new IllegalArgumentException throw IllegalArgumentException
("Too little dynamic range in luminance"); ("Too little dynamic range in luminance");
} }

View file

@ -77,7 +77,7 @@ namespace common {
if (x < -1 || x > width || y < -1 || y > height) { if (x < -1 || x > width || y < -1 || y > height) {
ostringstream s; ostringstream s;
s << "Transformed point out of bounds at " << x << "," << y; s << "Transformed point out of bounds at " << x << "," << y;
throw new ReaderException(s.str().c_str()); throw ReaderException(s.str().c_str());
} }
nudged = false; nudged = false;
if (x == -1) { if (x == -1) {
@ -103,7 +103,7 @@ namespace common {
if (x < -1 || x > width || y < -1 || y > height) { if (x < -1 || x > width || y < -1 || y > height) {
ostringstream s; ostringstream s;
s << "Transformed point out of bounds at " << x << "," << y; s << "Transformed point out of bounds at " << x << "," << y;
throw new ReaderException(s.str().c_str()); throw ReaderException(s.str().c_str());
} }
nudged = false; nudged = false;
if (x == -1) { if (x == -1) {

View file

@ -75,7 +75,7 @@ namespace reedsolomon {
cout << __FUNCTION__ << "\n"; cout << __FUNCTION__ << "\n";
#endif #endif
if (degree < 0) { if (degree < 0) {
throw new IllegalArgumentException("Degree must be non-negative"); throw IllegalArgumentException("Degree must be non-negative");
} }
if (coefficient == 0) { if (coefficient == 0) {
return zero_; return zero_;
@ -97,14 +97,14 @@ namespace reedsolomon {
int GF256::log(int a) { int GF256::log(int a) {
if (a == 0) { if (a == 0) {
throw new IllegalArgumentException("Cannot take the logarithm of 0"); throw IllegalArgumentException("Cannot take the logarithm of 0");
} }
return log_[a]; return log_[a];
} }
int GF256::inverse(int a) { int GF256::inverse(int a) {
if (a == 0) { 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]]; return exp_[255 - log_[a]];
} }

View file

@ -99,7 +99,7 @@ namespace reedsolomon {
GF256Poly *GF256Poly::addOrSubtract(GF256Poly *b) { GF256Poly *GF256Poly::addOrSubtract(GF256Poly *b) {
if (&field != &b->field) { if (&field != &b->field) {
throw new IllegalArgumentException("Fields must be the same"); throw IllegalArgumentException("Fields must be the same");
} }
if (isZero()) { if (isZero()) {
return b; return b;
@ -131,7 +131,7 @@ namespace reedsolomon {
GF256Poly *GF256Poly::multiply(GF256Poly *b) { GF256Poly *GF256Poly::multiply(GF256Poly *b) {
if (&field != &b->field) { if (&field != &b->field) {
throw new IllegalArgumentException("Fields must be the same"); throw IllegalArgumentException("Fields must be the same");
} }
if (isZero() || b->isZero()) { if (isZero() || b->isZero()) {
return field.getZero(); return field.getZero();
@ -172,7 +172,7 @@ namespace reedsolomon {
GF256Poly *GF256Poly::multiplyByMonomial(int degree, GF256Poly *GF256Poly::multiplyByMonomial(int degree,
int coefficient) { int coefficient) {
if (degree < 0) { if (degree < 0) {
throw new IllegalArgumentException("Degree must be non-negative"); throw IllegalArgumentException("Degree must be non-negative");
} }
if (coefficient == 0) { if (coefficient == 0) {
return field.getZero(); return field.getZero();

View file

@ -106,7 +106,7 @@ namespace reedsolomon {
// Divide rLastLast by rLast, with quotient q and remainder r // Divide rLastLast by rLast, with quotient q and remainder r
if (rLast->isZero()) { if (rLast->isZero()) {
// Oops, Euclidean algorithm already terminated? // Oops, Euclidean algorithm already terminated?
throw new ReedSolomonException("r_{i-1} was zero"); throw ReedSolomonException("r_{i-1} was zero");
} }
r = rLastLast; r = rLastLast;
Ref<GF256Poly> q(field.getZero()); Ref<GF256Poly> q(field.getZero());
@ -126,7 +126,7 @@ namespace reedsolomon {
int sigmaTildeAtZero = t->getCoefficient(0); int sigmaTildeAtZero = t->getCoefficient(0);
if (sigmaTildeAtZero == 0) { if (sigmaTildeAtZero == 0) {
throw new ReedSolomonException("sigmaTilde(0) was zero"); throw ReedSolomonException("sigmaTilde(0) was zero");
} }
int inverse = field.inverse(sigmaTildeAtZero); int inverse = field.inverse(sigmaTildeAtZero);
@ -165,7 +165,7 @@ namespace reedsolomon {
} }
} }
if (e != numErrors) { if (e != numErrors) {
throw new ReedSolomonException throw ReedSolomonException
("Error locator degree does not match number of roots"); ("Error locator degree does not match number of roots");
} }
return result; return result;

View file

@ -36,7 +36,7 @@ namespace qrcode {
bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() { bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() {
int dimension = bitMatrix->getDimension(); int dimension = bitMatrix->getDimension();
if ((dimension < 21) || (dimension & 0x03) != 1) { 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) { if (parsedFormatInfo_ != 0) {
return parsedFormatInfo_; return parsedFormatInfo_;
} }
throw new ReaderException("Could not decode format information"); throw ReaderException("Could not decode format information");
} }
Version *BitMatrixParser::readVersion() { Version *BitMatrixParser::readVersion() {
@ -121,7 +121,7 @@ namespace qrcode {
if (parsedVersion_ != 0) { if (parsedVersion_ != 0) {
return parsedVersion_; return parsedVersion_;
} }
throw new ReaderException("Could not decode version"); throw ReaderException("Could not decode version");
} }
ArrayRef<unsigned char> BitMatrixParser::readCodewords() { ArrayRef<unsigned char> BitMatrixParser::readCodewords() {
@ -177,7 +177,7 @@ namespace qrcode {
readingUp = !readingUp; // switch directions readingUp = !readingUp; // switch directions
} }
if (resultOffset != version->getTotalCodewords()) { if (resultOffset != version->getTotalCodewords()) {
throw new ReaderException("Did not read all codewords"); throw ReaderException("Did not read all codewords");
} }
return result; return result;
} }

View file

@ -67,7 +67,7 @@ namespace qrcode {
break; break;
} }
if (numCodewords != shorterBlocksTotalCodewords + 1) { 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--; longerBlocksStartAt--;
} }
@ -96,7 +96,7 @@ namespace qrcode {
} }
if ((size_t) rawCodewordsOffset != rawCodewords.size()) { if ((size_t) rawCodewordsOffset != rawCodewords.size()) {
throw new IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length");
} }
return result; return result;

View file

@ -30,7 +30,7 @@ namespace qrcode {
DataMask &DataMask::forReference(int reference) { DataMask &DataMask::forReference(int reference) {
if (reference < 0 || reference > 7) { 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]; return *DATA_MASKS[reference];
} }

View file

@ -27,18 +27,18 @@ namespace qrcode {
using namespace common; using namespace common;
using namespace std; using namespace std;
char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = { const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
' ', '$', '%', '*', '+', '-', '.', '/', ':' ' ', '$', '%', '*', '+', '-', '.', '/', ':'
}; };
char *DecodedBitStreamParser::ASCII = "ASCII"; const char *DecodedBitStreamParser::ASCII = "ASCII";
char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1"; const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1";
char *DecodedBitStreamParser::UTF8 = "UTF-8"; const char *DecodedBitStreamParser::UTF8 = "UTF-8";
char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS"; const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
char *DecodedBitStreamParser::EUC_JP = "EUC-JP"; const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
void DecodedBitStreamParser::append(ostream &ost, void DecodedBitStreamParser::append(ostream &ost,
unsigned char *bufIn, unsigned char *bufIn,
@ -59,7 +59,7 @@ namespace qrcode {
while (nFrom > 0) { while (nFrom > 0) {
size_t oneway = iconv(cd, &fromPtr, &nFrom, &toPtr, &nTo); size_t oneway = iconv(cd, &fromPtr, &nFrom, &toPtr, &nTo);
if (oneway == (size_t)(-1)) { if (oneway == (size_t)(-1)) {
throw new ReaderException("error converting characters"); throw ReaderException("error converting characters");
} }
} }
iconv_close(cd); iconv_close(cd);
@ -106,7 +106,7 @@ namespace qrcode {
if (count << 3 > bits->available()) { if (count << 3 > bits->available()) {
ostringstream s; ostringstream s;
s << "Count too large: " << count; 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++) { for (int i = 0; i < count; i++) {
readBytes[i] = (unsigned char) bits->readBits(8); 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 // upon decoding. I have seen ISO-8859-1 used as well as
// Shift_JIS -- without anything like an ECI designator to // Shift_JIS -- without anything like an ECI designator to
// give a hint. // give a hint.
char *encoding = guessEncoding(readBytes, nBytes); const char *encoding = guessEncoding(readBytes, nBytes);
append(result, readBytes, nBytes, encoding); append(result, readBytes, nBytes, encoding);
} }
@ -133,7 +133,7 @@ namespace qrcode {
if (threeDigitsBits >= 1000) { if (threeDigitsBits >= 1000) {
ostringstream s; ostringstream s;
s << "Illegal value for 3-digit unit: " << threeDigitsBits; 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 / 100];
bytes[i++] = ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]; bytes[i++] = ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10];
@ -146,7 +146,7 @@ namespace qrcode {
if (twoDigitsBits >= 100) { if (twoDigitsBits >= 100) {
ostringstream s; ostringstream s;
s << "Illegal value for 2-digit unit: " << twoDigitsBits; 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];
bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits % 10]; bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits % 10];
@ -156,7 +156,7 @@ namespace qrcode {
if (digitBits >= 10) { if (digitBits >= 10) {
ostringstream s; ostringstream s;
s << "Illegal value for digit unit: " << digitBits; 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]; bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
} }
@ -182,7 +182,7 @@ namespace qrcode {
append(result, bytes, nBytes, ASCII); append(result, bytes, nBytes, ASCII);
} }
char * const char *
DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) { DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
// Does it start with the UTF-8 byte order mark? then guess it's UTF-8 // Does it start with the UTF-8 byte order mark? then guess it's UTF-8
if (length > 3 && bytes[0] == (unsigned char) 0xEF && if (length > 3 && bytes[0] == (unsigned char) 0xEF &&
@ -262,7 +262,7 @@ namespace qrcode {
} else if (mode == &Mode::KANJI) { } else if (mode == &Mode::KANJI) {
decodeKanjiSegment(bits, result, count); decodeKanjiSegment(bits, result, count);
} else { } else {
throw new ReaderException("Unsupported mode indicator"); throw ReaderException("Unsupported mode indicator");
} }
} }
} while (mode != &Mode::TERMINATOR); } while (mode != &Mode::TERMINATOR);

View file

@ -38,13 +38,13 @@ namespace qrcode {
class DecodedBitStreamParser { class DecodedBitStreamParser {
private: private:
static char ALPHANUMERIC_CHARS[]; static const char ALPHANUMERIC_CHARS[];
static char *ASCII; static const char *ASCII;
static char *ISO88591; static const char *ISO88591;
static char *UTF8; static const char *UTF8;
static char *SHIFT_JIS; static const char *SHIFT_JIS;
static char *EUC_JP; static const char *EUC_JP;
static void decodeKanjiSegment(Ref<BitSource> bits, static void decodeKanjiSegment(Ref<BitSource> bits,
ostringstream &result, ostringstream &result,
@ -58,7 +58,7 @@ namespace qrcode {
static void decodeNumericSegment(Ref<BitSource> bits, static void decodeNumericSegment(Ref<BitSource> bits,
ostringstream &result, ostringstream &result,
int count); 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, static void append(ostream &ost, unsigned char *bufIn,
size_t nIn, const char *src); size_t nIn, const char *src);

View file

@ -45,9 +45,8 @@ namespace qrcode {
try { try {
rsDecoder_.decode(codewordInts, numECCodewords); rsDecoder_.decode(codewordInts, numECCodewords);
} }
catch (ReedSolomonException *ex) { catch (ReedSolomonException ex) {
ReaderException *rex = new ReaderException(ex->what()); ReaderException rex(ex.what());
delete ex;
throw rex; throw rex;
} }

View file

@ -41,7 +41,7 @@ namespace qrcode {
int ordinal() { return ordinal_; } int ordinal() { return ordinal_; }
static ErrorCorrectionLevel& forBits(int bits) { static ErrorCorrectionLevel& forBits(int bits) {
if (bits < 0 || bits >= N_LEVELS) { 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]; return *FOR_BITS[bits];
} }

View file

@ -52,7 +52,7 @@ namespace qrcode {
default: default:
ostringstream s; ostringstream s;
s << "Illegal mode bits: " << bits; s << "Illegal mode bits: " << bits;
throw new ReaderException(s.str().c_str()); throw ReaderException(s.str().c_str());
} }
} }

View file

@ -63,14 +63,14 @@ namespace qrcode {
Version *Version::getProvisionalVersionForDimension(int dimension) { Version *Version::getProvisionalVersionForDimension(int dimension) {
if (dimension %4 != 1) { 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); return Version::getVersionForNumber((dimension - 17) >> 2);
} }
Version *Version::getVersionForNumber(int versionNumber) { Version *Version::getVersionForNumber(int versionNumber) {
if (versionNumber < 1 || versionNumber > 40) { 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; N_VERSIONS;
return VERSIONS[versionNumber - 1]; return VERSIONS[versionNumber - 1];

View file

@ -211,7 +211,7 @@ namespace qrcode {
return center; return center;
} }
throw new ReaderException("Could not find alignment pattern"); throw ReaderException("Could not find alignment pattern");
} }
} }

View file

@ -86,13 +86,12 @@ namespace qrcode {
estAlignmentY, estAlignmentY,
(float) i); (float) i);
break; break;
} catch (ReaderException *re) { } catch (ReaderException re) {
// try next round // try next round
delete re;
} }
} }
if (alignmentPattern == 0) { 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: case 3:
ostringstream s; ostringstream s;
s << "Bad dimension: " << dimension; s << "Bad dimension: " << dimension;
throw new ReaderException(s.str().c_str()); throw ReaderException(s.str().c_str());
} }
return dimension; return dimension;
} }

View file

@ -318,7 +318,7 @@ namespace qrcode {
if (size < 3) { if (size < 3) {
// Couldn't find enough finder patterns // 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) { if (size == 3) {

View file

@ -41,9 +41,8 @@ namespace common {
valarray<int> histogram(histogramRaw, 16); valarray<int> histogram(histogramRaw, 16);
BlackPointEstimator::estimate(histogram); BlackPointEstimator::estimate(histogram);
CPPUNIT_FAIL("Should have thrown an exception"); CPPUNIT_FAIL("Should have thrown an exception");
} catch (IllegalArgumentException* ie) { } catch (IllegalArgumentException ie) {
// good // good
delete ie;
} }
} }
} }

View file

@ -97,9 +97,8 @@ namespace reedsolomon {
checkQRRSDecode(received); checkQRRSDecode(received);
cout << "expected exception!\n"; cout << "expected exception!\n";
CPPUNIT_FAIL("should not happen!"); CPPUNIT_FAIL("should not happen!");
} catch (ReedSolomonException *e) { } catch (ReedSolomonException e) {
// expected // expected
delete e;
} catch (...) { } catch (...) {
CPPUNIT_FAIL("unexpected exception!"); CPPUNIT_FAIL("unexpected exception!");
} }

View file

@ -40,9 +40,8 @@ namespace qrcode {
ErrorCorrectionLevel::forBits(4); ErrorCorrectionLevel::forBits(4);
CPPUNIT_FAIL("should have thrown an exception"); CPPUNIT_FAIL("should have thrown an exception");
} }
catch (ReaderException *ex) { catch (ReaderException ex) {
// expected // expected
delete ex;
} }
} }
} }

View file

@ -36,9 +36,8 @@ namespace qrcode {
Mode::forBits(0x10); Mode::forBits(0x10);
CPPUNIT_FAIL("should have thrown an exception"); CPPUNIT_FAIL("should have thrown an exception");
} }
catch (ReaderException *ex) { catch (ReaderException ex) {
// expected // expected
delete ex;
} }
} }

View file

@ -56,9 +56,8 @@ namespace qrcode {
try { try {
Version::getVersionForNumber(0); Version::getVersionForNumber(0);
CPPUNIT_FAIL("Should have thrown an exception"); CPPUNIT_FAIL("Should have thrown an exception");
} catch (ReaderException *re) { } catch (ReaderException re) {
// good // good
delete re;
} }
for (int i = 1; i <= 40; i++) { for (int i = 1; i <= 40; i++) {
checkVersion(Version::getVersionForNumber(i), i, 4*i + 17); checkVersion(Version::getVersionForNumber(i), i, 4*i + 17);

View file

@ -180,14 +180,12 @@ using namespace qrcode;
decoderResult = [TwoDDecoderResult resultWithText:resultString decoderResult = [TwoDDecoderResult resultWithText:resultString
points:points]; points:points];
} catch (ReaderException *rex) { } catch (ReaderException rex) {
NSLog(@"failed to decode, caught ReaderException '%s'", NSLog(@"failed to decode, caught ReaderException '%s'",
rex->what()); rex.what());
delete rex; } catch (IllegalArgumentException iex) {
} catch (IllegalArgumentException *iex) {
NSLog(@"failed to decode, caught IllegalArgumentException '%s'", NSLog(@"failed to decode, caught IllegalArgumentException '%s'",
iex->what()); iex.what());
delete iex;
} catch (...) { } catch (...) {
NSLog(@"Caught unknown exception!"); NSLog(@"Caught unknown exception!");
} }