Add exception generation to error logging

This commit puts basic exception support into the elog class.
All errors will generate an exception with this commit.

This will most likely change over to using the dbus exception
class as a base in the future but that change will be transperent
to the users.

Change-Id: Ibd02d4c204393a0cfb156805360161759cb6631e
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/elog.hpp b/elog.hpp
index 090b5e9..b445a0e 100644
--- a/elog.hpp
+++ b/elog.hpp
@@ -66,6 +66,24 @@
 
 } // namespace details
 
+/**
+ * @brief Error log exception base class
+ *
+ * This allows people to capture all error log exceptions if desired
+ */
+class elogExceptionBase : public std::exception {};
+
+/**
+ * @brief Error log exception class
+ *
+ * This is for capturing specific error log exceptions
+ */
+template <typename T> class elogException : public elogExceptionBase
+{
+public:
+    const char* what() const noexcept override { return T::err_code; }
+};
+
 /** @fn commit()
  *  @brief Create an error log entry based on journal
  *          entry with a specified MSG_ID
@@ -98,6 +116,9 @@
 
     log<T::L>(T::err_msg,
               details::deduce_entry_type<Args>{i_args}.get()...);
+
+    // Now throw an exception for this error
+    throw elogException<T>();
 }
 
 } // namespace logging
diff --git a/logging_test.cpp b/logging_test.cpp
index 5f153c1..9a638c3 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -70,9 +70,16 @@
     // TEST 3 - Create error log with 2 meta data fields (rvalue and lvalue)
     number = 0x1234;
     const char *test_string = "/tmp/test_string/";
-    elog<file_not_found>(file_not_found::errnum(number),
-                         file_not_found::file_path(test_string),
-                         file_not_found::file_name("elog_test_3.txt"));
+    try
+    {
+        elog<file_not_found>(file_not_found::errnum(number),
+                             file_not_found::file_path(test_string),
+                             file_not_found::file_name("elog_test_3.txt"));
+    }
+    catch (elogException<file_not_found>& e)
+    {
+        std::cout << "elog exception caught: " << e.what() << std::endl;
+    }
 
     // Now read back and verify our data made it into the journal
     rc = validate_journal(file_not_found::errnum::str_short,
@@ -92,10 +99,16 @@
 
     // TEST 4 - Create error log with previous entry use
     number = 0xFEDC;
-    elog<file_not_found>(file_not_found::errnum(number),
-                         prev_entry<file_not_found::file_path>(),
-                         file_not_found::file_name("elog_test_4.txt"));
-
+    try
+    {
+        elog<file_not_found>(file_not_found::errnum(number),
+                             prev_entry<file_not_found::file_path>(),
+                             file_not_found::file_name("elog_test_4.txt"));
+    }
+    catch (elogExceptionBase& e)
+    {
+        std::cout << "elog exception caught: " << e.what() << std::endl;
+    }
     // Now read back and verify our data made it into the journal
     rc = validate_journal(file_not_found::errnum::str_short,
                           std::to_string(number).c_str());