From 75149be061fab7c8d7ce0e24e0c9ad0e52d0dd5b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 13 Jul 2016 14:19:26 -0400 Subject: MAINT-5011: Wrap thrown png_const_charp in new PngError class derived from std::runtime_error. --- indra/llimage/llpngwrapper.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index aad139f570..4292f29acc 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -31,6 +31,13 @@ #include "llimage.h" #include "llpngwrapper.h" +#include + +struct PngError: public std::runtime_error +{ + PngError(png_const_charp msg): std::runtime_error(msg) {} +}; + // --------------------------------------------------------------------------- // LLPngWrapper // --------------------------------------------------------------------------- @@ -75,11 +82,10 @@ BOOL LLPngWrapper::isValidPng(U8* src) } // Called by the libpng library when a fatal encoding or decoding error -// occurs. We simply throw the error message and let our try/catch -// block clean up. +// occurs. We throw PngError and let our try/catch block clean up. void LLPngWrapper::errorHandler(png_structp png_ptr, png_const_charp msg) { - throw msg; + throw PngError(msg); } // Called by the libpng library when reading (decoding) the PNG file. We @@ -129,7 +135,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf this, &errorHandler, NULL); if (mReadPngPtr == NULL) { - throw "Problem creating png read structure"; + throw PngError("Problem creating png read structure"); } // Allocate/initialize the memory for image information. @@ -187,9 +193,9 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf mFinalSize = dataPtr.mOffset; } - catch (png_const_charp msg) + catch (const PngError& msg) { - mErrorMessage = msg; + mErrorMessage = msg.what(); releaseResources(); return (FALSE); } @@ -288,14 +294,14 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) if (mColorType == -1) { - throw "Unsupported image: unexpected number of channels"; + throw PngError("Unsupported image: unexpected number of channels"); } mWritePngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &errorHandler, NULL); if (!mWritePngPtr) { - throw "Problem creating png write structure"; + throw PngError("Problem creating png write structure"); } mWriteInfoPtr = png_create_info_struct(mWritePngPtr); @@ -339,9 +345,9 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) png_write_end(mWritePngPtr, mWriteInfoPtr); mFinalSize = dataPtr.mOffset; } - catch (png_const_charp msg) + catch (const PngError& msg) { - mErrorMessage = msg; + mErrorMessage = msg.what(); releaseResources(); return (FALSE); } -- cgit v1.2.3 From 636ce117bb1b3bda30ff725d41b50ed2c48e4bf0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 14 Jul 2016 10:35:56 -0400 Subject: MAINT-5011: Per NickyD, put PngError in anonymous namespace. --- indra/llimage/llpngwrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 4292f29acc..531859cbc9 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -33,10 +33,12 @@ #include +namespace { struct PngError: public std::runtime_error { PngError(png_const_charp msg): std::runtime_error(msg) {} }; +} // anonymous namespace // --------------------------------------------------------------------------- // LLPngWrapper -- cgit v1.2.3 From 9c49a6c91dd9b5bbe811fcd91d8992ed6bac33e7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 19 Jul 2016 16:25:25 -0400 Subject: MAINT-5011: Introduce LLException base class for viewer exceptions. This also introduces LLContinueError for exceptions which should interrupt some part of viewer processing (e.g. the current coroutine) but should attempt to let the viewer session proceed. Derive all existing viewer exception classes from LLException rather than from std::runtime_error or std::logic_error. Use BOOST_THROW_EXCEPTION() rather than plain 'throw' to enrich the thrown exception with source file, line number and containing function. --- indra/llimage/llpngwrapper.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 531859cbc9..0b7d4c717f 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -31,12 +31,13 @@ #include "llimage.h" #include "llpngwrapper.h" -#include +#include "llexception.h" +#include namespace { -struct PngError: public std::runtime_error +struct PngError: public LLException { - PngError(png_const_charp msg): std::runtime_error(msg) {} + PngError(png_const_charp msg): LLException(msg) {} }; } // anonymous namespace @@ -87,7 +88,7 @@ BOOL LLPngWrapper::isValidPng(U8* src) // occurs. We throw PngError and let our try/catch block clean up. void LLPngWrapper::errorHandler(png_structp png_ptr, png_const_charp msg) { - throw PngError(msg); + BOOST_THROW_EXCEPTION(PngError(msg)); } // Called by the libpng library when reading (decoding) the PNG file. We @@ -137,7 +138,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf this, &errorHandler, NULL); if (mReadPngPtr == NULL) { - throw PngError("Problem creating png read structure"); + BOOST_THROW_EXCEPTION(PngError("Problem creating png read structure")); } // Allocate/initialize the memory for image information. @@ -296,14 +297,14 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) if (mColorType == -1) { - throw PngError("Unsupported image: unexpected number of channels"); + BOOST_THROW_EXCEPTION(PngError("Unsupported image: unexpected number of channels")); } mWritePngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &errorHandler, NULL); if (!mWritePngPtr) { - throw PngError("Problem creating png write structure"); + BOOST_THROW_EXCEPTION(PngError("Problem creating png write structure")); } mWriteInfoPtr = png_create_info_struct(mWritePngPtr); -- cgit v1.2.3