summaryrefslogtreecommitdiff
path: root/indra/llcommon/llexception.h
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2016-07-19 16:25:25 -0400
committerNat Goodspeed <nat@lindenlab.com>2016-07-19 16:25:25 -0400
commit9c49a6c91dd9b5bbe811fcd91d8992ed6bac33e7 (patch)
treeac1d2b5683b0df287448373b79092981115d9410 /indra/llcommon/llexception.h
parent47d93e4f65493977217cfed53ff68eb926cf9bb7 (diff)
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.
Diffstat (limited to 'indra/llcommon/llexception.h')
-rw-r--r--indra/llcommon/llexception.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/indra/llcommon/llexception.h b/indra/llcommon/llexception.h
new file mode 100644
index 0000000000..3ac2f4762f
--- /dev/null
+++ b/indra/llcommon/llexception.h
@@ -0,0 +1,63 @@
+/**
+ * @file llexception.h
+ * @author Nat Goodspeed
+ * @date 2016-06-29
+ * @brief Types needed for generic exception handling
+ *
+ * $LicenseInfo:firstyear=2016&license=viewerlgpl$
+ * Copyright (c) 2016, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+#if ! defined(LL_LLEXCEPTION_H)
+#define LL_LLEXCEPTION_H
+
+#include <stdexcept>
+#include <boost/exception/exception.hpp>
+
+/**
+ * LLException is intended as the common base class from which all
+ * viewer-specific exceptions are derived. It is itself a subclass of
+ * boost::exception; use catch (const boost::exception& e) clause to log the
+ * string from boost::diagnostic_information(e).
+ *
+ * Since it is also derived from std::exception, a generic catch (const
+ * std::exception&) should also work, though what() is unlikely to be as
+ * informative as boost::diagnostic_information().
+ *
+ * Please use BOOST_THROW_EXCEPTION()
+ * http://www.boost.org/doc/libs/release/libs/exception/doc/BOOST_THROW_EXCEPTION.html
+ * to throw viewer exceptions whenever possible. This enriches the exception's
+ * diagnostic_information() with the source file, line and containing function
+ * of the BOOST_THROW_EXCEPTION() macro.
+ *
+ * There may be circumstances in which it would be valuable to distinguish an
+ * exception explicitly thrown by viewer code from an exception thrown by
+ * (say) a third-party library. Catching (const LLException&) supports such
+ * usage. However, most of the value of this base class is in the
+ * diagnostic_information() available via Boost.Exception.
+ */
+struct LLException:
+ public std::runtime_error,
+ public boost::exception
+{
+ LLException(const std::string& what):
+ std::runtime_error(what)
+ {}
+};
+
+/**
+ * The point of LLContinueError is to distinguish exceptions that need not
+ * terminate the whole viewer session. In general, an uncaught exception will
+ * be logged and will crash the viewer. However, though an uncaught exception
+ * derived from LLContinueError will still be logged, the viewer will attempt
+ * to continue processing.
+ */
+struct LLContinueError: public LLException
+{
+ LLContinueError(const std::string& what):
+ LLException(what)
+ {}
+};
+
+#endif /* ! defined(LL_LLEXCEPTION_H) */