From 5b233bba3f885cd7f6202a70677d7ae2970bdfeb Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 13 Jul 2016 14:28:45 -0400 Subject: MAINT-5011: Remove alarming ll_kdu_error() function whose body reads: // *FIX: This exception is bad, bad, bad. It gets thrown from a // destructor which can lead to immediate program termination! throw "ll_kdu_error() throwing an exception"; which would be bad indeed... if ll_kdu_error() were ever actually referenced by anything! --- indra/llkdu/llimagej2ckdu.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'indra/llkdu') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 282c859e9e..94c7dbdd23 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -128,13 +128,6 @@ private: S32 mRowGap; }; -void ll_kdu_error( void ) -{ - // *FIX: This exception is bad, bad, bad. It gets thrown from a - // destructor which can lead to immediate program termination! - throw "ll_kdu_error() throwing an exception"; -} - // Stuff for new kdu error handling class LLKDUMessageWarning : public kdu_message { -- cgit v1.2.3 From 21e8352de6c4d662ffdb44d31294ce9caca86517 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 13 Jul 2016 14:42:44 -0400 Subject: MAINT-5011: Introduce KduError instead of throw/catch const char*. KduError is derived from std::runtime_error, so the message string becomes its what() message. --- indra/llkdu/llimagej2ckdu.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'indra/llkdu') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 94c7dbdd23..50c2e03cd4 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -34,6 +34,13 @@ #include "kdu_block_coding.h" +#include + +struct KduError: public std::runtime_error +{ + KduError(const std::string& msg): std::runtime_error(msg) {} +}; + class kdc_flow_control { public: @@ -171,7 +178,7 @@ void LLKDUMessageError::flush(bool end_of_message) { if (end_of_message) { - throw "KDU throwing an exception"; + throw KduError("LLKDUMessageError::flush()"); } } @@ -415,9 +422,9 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco mTPosp->x = 0; } } - catch (const char* msg) + catch (const KduError& msg) { - base.setLastError(ll_safe_string(msg)); + base.setLastError(msg.what()); return FALSE; } catch (...) @@ -505,9 +512,9 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco return FALSE; } } - catch (const char* msg) + catch (const KduError& msg) { - base.setLastError(ll_safe_string(msg)); + base.setLastError(msg.what()); base.decodeFailed(); cleanupCodeStream(); return TRUE; // done @@ -698,9 +705,9 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co base.updateData(); // set width, height delete[] output_buffer; } - catch(const char* msg) + catch(const KduError& msg) { - base.setLastError(ll_safe_string(msg)); + base.setLastError(msg.what()); return FALSE; } catch( ... ) @@ -722,9 +729,9 @@ BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) setupCodeStream(base, FALSE, MODE_FAST); return TRUE; } - catch (const char* msg) + catch (const KduError& msg) { - base.setLastError(ll_safe_string(msg)); + base.setLastError(msg.what()); return FALSE; } catch (...) -- cgit v1.2.3 From d7c904632b9dac112228092952f993569477366c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 14 Jul 2016 10:26:57 -0400 Subject: MAINT-5011: On advice from NickyD, say KDUError not KduError. Also place KDUError into anonymous namespace to emphasize that it's entirely local to this .cpp file. --- indra/llkdu/llimagej2ckdu.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'indra/llkdu') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 50c2e03cd4..2a5b24fbc1 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -36,10 +36,12 @@ #include -struct KduError: public std::runtime_error +namespace { +struct KDUError: public std::runtime_error { - KduError(const std::string& msg): std::runtime_error(msg) {} + KDUError(const std::string& msg): std::runtime_error(msg) {} }; +} // anonymous namespace class kdc_flow_control { @@ -178,7 +180,7 @@ void LLKDUMessageError::flush(bool end_of_message) { if (end_of_message) { - throw KduError("LLKDUMessageError::flush()"); + throw KDUError("LLKDUMessageError::flush()"); } } @@ -422,7 +424,7 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco mTPosp->x = 0; } } - catch (const KduError& msg) + catch (const KDUError& msg) { base.setLastError(msg.what()); return FALSE; @@ -512,7 +514,7 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco return FALSE; } } - catch (const KduError& msg) + catch (const KDUError& msg) { base.setLastError(msg.what()); base.decodeFailed(); @@ -705,7 +707,7 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co base.updateData(); // set width, height delete[] output_buffer; } - catch(const KduError& msg) + catch(const KDUError& msg) { base.setLastError(msg.what()); return FALSE; @@ -729,7 +731,7 @@ BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) setupCodeStream(base, FALSE, MODE_FAST); return TRUE; } - catch (const KduError& msg) + catch (const KDUError& msg) { base.setLastError(msg.what()); return FALSE; -- 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/llkdu/llimagej2ckdu.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/llkdu') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 2a5b24fbc1..fa58931407 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -34,12 +34,13 @@ #include "kdu_block_coding.h" -#include +#include "llexception.h" +#include namespace { -struct KDUError: public std::runtime_error +struct KDUError: public LLException { - KDUError(const std::string& msg): std::runtime_error(msg) {} + KDUError(const std::string& msg): LLException(msg) {} }; } // anonymous namespace @@ -180,7 +181,7 @@ void LLKDUMessageError::flush(bool end_of_message) { if (end_of_message) { - throw KDUError("LLKDUMessageError::flush()"); + BOOST_THROW_EXCEPTION(KDUError("LLKDUMessageError::flush()")); } } -- cgit v1.2.3 From 5e9d2f57c82a57307a48afea09aa539b9fa80abf Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Aug 2016 11:36:24 -0400 Subject: MAINT-5011: Use LLTHROW() instead of plain BOOST_THROW_EXCEPTION(). A level of preprocessor indirection lets us later change the implementation if desired. --- indra/llkdu/llimagej2ckdu.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/llkdu') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index fa58931407..8dd0b6d458 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -35,7 +35,6 @@ #include "kdu_block_coding.h" #include "llexception.h" -#include namespace { struct KDUError: public LLException @@ -181,7 +180,7 @@ void LLKDUMessageError::flush(bool end_of_message) { if (end_of_message) { - BOOST_THROW_EXCEPTION(KDUError("LLKDUMessageError::flush()")); + LLTHROW(KDUError("LLKDUMessageError::flush()")); } } -- cgit v1.2.3