[MOAB-dev] commit/MOAB: danwu: Create an example file TestErrorHandling.cpp under moab/examples, to demonstrate enhanced error handling of MOAB (e.g. print out the stack trace when an error occurs). This example creates contrived errors for testing, without calling actual MOAB routines.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jan 15 10:42:43 CST 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/4e67f65528b4/
Changeset:   4e67f65528b4
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-01-15 17:42:19
Summary:     Create an example file TestErrorHandling.cpp under moab/examples, to demonstrate enhanced error handling of MOAB (e.g. print out the stack trace when an error occurs). This example creates contrived errors for testing, without calling actual MOAB routines.

Affected #:  2 files

diff --git a/examples/TestErrorHandling.cpp b/examples/TestErrorHandling.cpp
new file mode 100644
index 0000000..3108b99
--- /dev/null
+++ b/examples/TestErrorHandling.cpp
@@ -0,0 +1,89 @@
+/** @example TestErrorHandling.cpp
+ * Description: Demonstrates enhanced error handling of MOAB.\n
+ * This example creates contrived errors to test MOAB's trace back error handler.\n
+ *
+ * To run: ./TestErrorHandling\n
+ */
+
+#include "moab/Core.hpp"
+#include <iostream>
+
+using namespace moab;
+using namespace std;
+
+// Call hierarchy: A calls B, and B calls C
+ErrorInfo FunctionC(int n)
+{
+  if (1 == n) {
+    // No error occurs
+    return ERROR_INFO_SUCCESS;
+  }
+  else if (2 == n) {
+    // Simulate MB_FILE_WRITE_ERROR
+    SET_ERR1(MB_FILE_WRITE_ERROR, "FunctionC created a contrived error MB_ENTITY_MB_FILE_WRITE_ERROR.");
+  }
+  else if (3 == n) {
+    // Simulate MB_NOT_IMPLEMENTED
+    ErrorInfo err_info(MB_NOT_IMPLEMENTED);
+    err_info << "n = " << n << ", FunctionC created a contrived MB_NOT_IMPLEMENTED (this message is built with C++ streaming).";
+    SET_ERR(err_info);
+  }
+
+  return ERROR_INFO_SUCCESS;
+}
+
+ErrorInfo FunctionB(int n)
+{
+  ErrorInfo err_info = FunctionC(n);CHK_ERR(err_info);
+
+  return ERROR_INFO_SUCCESS;
+}
+
+ErrorInfo FunctionA(int n)
+{
+  ErrorInfo err_info = FunctionB(n);CHK_ERR(err_info);
+
+  return ERROR_INFO_SUCCESS;
+}
+
+// In this test case, no error occurs in the call hierarchy
+ErrorInfo Test_1()
+{
+  ErrorInfo err_code = FunctionA(1);CHK_ERR(err_code);
+
+  return ERROR_INFO_SUCCESS;
+}
+
+// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC
+ErrorInfo Test_2()
+{
+  ErrorInfo err_code = FunctionA(2);CHK_ERR(err_code);
+
+  return ERROR_INFO_SUCCESS;
+}
+
+// In this test case, MB_NOT_IMPLEMENTED is returned by FunctionC
+// The error message is built with C++ streaming
+ErrorInfo Test_3()
+{
+  ErrorInfo err_code = FunctionA(3);CHK_ERR(err_code);
+
+  return ERROR_INFO_SUCCESS;
+}
+
+int main()
+{
+  cout << "--------------------Running test case 1 start--------------------" << endl;
+  Test_1();
+  cout << "--------------------Running test case 1 end----------------------\n" << endl;
+
+  cout << "--------------------Running test case 2 start--------------------" << endl;
+  Test_2();
+  cout << "--------------------Running test case 2 end----------------------\n" << endl;
+
+  cout << "--------------------Running test case 3 start--------------------" << endl;
+  Test_3();
+  cout << "--------------------Running test case 3 end----------------------\n" << endl;
+
+  return 0;
+}

diff --git a/examples/makefile b/examples/makefile
index a6e3d1f..5f64461 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -7,7 +7,7 @@ include ${MOAB_DIR}/lib/iMesh-Defs.inc
 # MESH_DIR is the directory containing mesh files that come with MOAB source
 MESH_DIR="../MeshFiles/unittest"
 
-EXAMPLES = HelloMOAB GetEntities SetsNTags StructuredMeshSimple DirectAccessWithHoles DirectAccessNoHoles 
+EXAMPLES = HelloMOAB GetEntities SetsNTags StructuredMeshSimple DirectAccessWithHoles DirectAccessNoHoles TestErrorHandling
 PAREXAMPLES = HelloParMOAB ReduceExchangeTags LloydRelaxation
 F90EXAMPLES = DirectAccessNoHolesF90 PushParMeshIntoMoabF90
 EXOIIEXAMPLES = TestExodusII
@@ -27,7 +27,7 @@ LloydRelaxation: LloydRelaxation.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 StructuredMeshSimple : StructuredMeshSimple.o ${MOAB_LIBDIR}/libMOAB.la
-	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} 
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 DirectAccessWithHoles: DirectAccessWithHoles.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
@@ -42,7 +42,7 @@ ReduceExchangeTags : ReduceExchangeTags.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 HelloParMOAB: HelloParMOAB.o ${MOAB_LIBDIR}/libMOAB.la
-	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} 
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 TestExodusII: TestExodusII.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
@@ -51,10 +51,13 @@ point_in_elem_search: point_in_elem_search.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 PushParMeshIntoMoabF90: PushParMeshIntoMoabF90.o
-	${MOAB_CXX} -o $@ $< ${IMESH_LIBS} -lgfortran -L/usr/lib/openmpi/lib -lmpi_f90 -lmpi_f77 -lmpi -lopen-rte -lopen-pal -ldl 
+	${MOAB_CXX} -o $@ $< ${IMESH_LIBS} -lgfortran -L/usr/lib/openmpi/lib -lmpi_f90 -lmpi_f77 -lmpi -lopen-rte -lopen-pal -ldl
 
 DeformMeshRemap: DeformMeshRemap.o ${MOAB_LIBDIR}/libMOAB.la
-	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} -lmbcoupler ${MOAB_LIBS_LINK} 
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK} -lmbcoupler ${MOAB_LIBS_LINK}
+
+TestErrorHandling: TestErrorHandling.o ${MOAB_LIBDIR}/libMOAB.la
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
 clean:
 	rm -rf *.o ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES}

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list