[Lemon-commits] [lemon_svn] klao: r647 - in hugo/trunk/src: include test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:40:45 CET 2006
Author: klao
Date: Fri Apr 30 00:39:17 2004
New Revision: 647
Added:
hugo/trunk/src/include/error.h
hugo/trunk/src/test/error_test.cc
Modified:
hugo/trunk/src/test/ (props changed)
hugo/trunk/src/test/makefile
Log:
Basic error handling facilities
(and possibly a g++-3.4.0 bug)
Added: hugo/trunk/src/include/error.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/include/error.h Fri Apr 30 00:39:17 2004
@@ -0,0 +1,64 @@
+// -*- C++ -*- //
+
+#ifndef HUGO_ERROR_H
+#define HUGO_ERROR_H
+
+//! \file
+//! \brief Basic error handling (signaling) routines.
+
+#include <string>
+#include <sstream>
+
+
+namespace hugo {
+
+ /**
+ * \brief Generic exception class.
+ *
+ * \todo Do we need this?
+ *
+ * \todo Don't we need different kind of exceptions for different kind
+ * of errors?
+ * Shouldn't we use <stdexcept> instead?
+ */
+ class Exception : public std::exception {
+ protected:
+ std::ostringstream buf;
+ public:
+ Exception() {}
+ explicit Exception(const std::string &s) { buf << s; }
+ Exception(const Exception &e) { buf << e.buf.str(); }
+ virtual ~Exception() throw() {}
+
+ virtual const char* what() const throw() {
+ return buf.str().c_str();
+ }
+
+ Exception& operator<<(std::string const& s) { buf << s; return *this; }
+ Exception& operator<<(char const *s) { buf << s; return *this; }
+ Exception& operator<<(int i) { buf << i; return *this; }
+ };
+
+ /**
+ * \brief Generic error signaling function.
+ *
+ * \todo Do we really need this? Is it helpful?
+ */
+ inline void fault(const std::string &msg) {
+ throw Exception(msg);
+ }
+
+ /**
+ * \brief Macro for mark not yet implemented features.
+ *
+ * \todo Is this the right place for this? It should be used only in
+ * modules under development.
+ */
+
+# define FIXME(msg) \
+ do { throw ::hugo::Exception("FIXME: " msg) << " (in: " \
+ << __FILE__ << ", " << __LINE__ << ")"; \
+ } while(false)
+
+}
+#endif // HUGO_ERROR_H
Added: hugo/trunk/src/test/error_test.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/test/error_test.cc Fri Apr 30 00:39:17 2004
@@ -0,0 +1,57 @@
+#include <iostream>
+
+#include <error.h>
+
+using namespace hugo;
+using std::cout;
+using std::endl;
+
+void faulty_fn() {
+ fault("This is a fault message");
+}
+
+void exception_fn() {
+ throw Exception("This is a fn throwing excpt with some args: ")
+ << 5 << ", " << 18;
+}
+
+void unfinished_fn() {
+ FIXME("unfinished_fn() is unfinished!");
+}
+
+
+int main() {
+ bool no_errors = false;
+
+ try {
+ cout << "Trying a faulty function\n";
+ faulty_fn();
+ no_errors = true;
+ cout << "FAILED!\n";
+ }
+ catch(const Exception &e) {
+ cout << "E: " << e.what() << endl;
+ }
+
+ try {
+ cout << "Trying a function throwing Exception\n";
+ exception_fn();
+ no_errors = true;
+ cout << "FAILED!\n";
+ }
+ catch(const Exception &e) {
+ cout << "E: " << e.what() << endl;
+ }
+
+ try {
+ cout << "Trying a function using FIXME\n";
+ unfinished_fn();
+ no_errors = true;
+ cout << "FAILED!\n";
+ }
+ catch(const Exception &e) {
+ cout << "E: " << e.what() << endl;
+ }
+
+ return no_errors ? 1 : 0;
+}
Modified: hugo/trunk/src/test/makefile
==============================================================================
--- hugo/trunk/src/test/makefile (original)
+++ hugo/trunk/src/test/makefile Fri Apr 30 00:39:17 2004
@@ -2,7 +2,7 @@
CXXFLAGS += -Wall -O3 -ansi -pedantic $(INCLUDEDIRS)
#LEDAROOT ?= /ledasrc/LEDA-4.1
-BINARIES = dijkstra_heap_test unionfind_test
+BINARIES = dijkstra_heap_test unionfind_test error_test
ifdef GCCVER
CXX := g++-$(GCCVER)
More information about the Lemon-commits
mailing list