From 83bbfa4d9d418607ef5e3bbb906fc0d271901c8a Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Sat, 30 Oct 2010 21:09:18 +0200
Subject: [PATCH] add a WcclError exception class

---
 libwccl/CMakeLists.txt |  1 +
 libwccl/exception.cpp  | 43 ++++++++++++++++++++++++++++++++++++++++++
 libwccl/exception.h    | 43 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 libwccl/exception.cpp
 create mode 100644 libwccl/exception.h

diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt
index e8fcba5..fd867ce 100644
--- a/libwccl/CMakeLists.txt
+++ b/libwccl/CMakeLists.txt
@@ -12,6 +12,7 @@ set(LIBS ${LIBS} ${Boost_LIBRARIES})
 
 SET(libwccl_STAT_SRC
 	bool.cpp
+	exception.cpp
 	main.cpp
 	position.cpp
 	sentencecontext.cpp
diff --git a/libwccl/exception.cpp b/libwccl/exception.cpp
new file mode 100644
index 0000000..46c5cc1
--- /dev/null
+++ b/libwccl/exception.cpp
@@ -0,0 +1,43 @@
+#include <libwccl/exception.h>
+#include <sstream>
+
+namespace Wccl {
+
+WcclError::WcclError(const std::string &what)
+ : PwrNlp::PwrNlpError(what)
+{
+}
+
+WcclError::~WcclError() throw()
+{
+}
+
+std::string WcclError::scope() const
+{
+	return "Wccl";
+}
+
+FileNotFound::FileNotFound(const std::string& filename,
+		const std::string& paths, const std::string& where)
+	: WcclError("File not found: " + filename), filename(filename),
+	paths(paths), where(where)
+{
+}
+
+FileNotFound::~FileNotFound() throw()
+{
+}
+
+std::string FileNotFound::info() const
+{
+	std::ostringstream ss;
+	if (where.empty()) {
+		ss << "File ";
+	} else {
+		ss << where << " file ";
+	}
+	ss << "'" << filename << "' not found in search path " << paths;
+	return ss.str();
+}
+
+} /* end ns Wccl */
diff --git a/libwccl/exception.h b/libwccl/exception.h
new file mode 100644
index 0000000..2d52855
--- /dev/null
+++ b/libwccl/exception.h
@@ -0,0 +1,43 @@
+#ifndef LIBWCCL_EXCEPTION_H
+#define LIBWCCL_EXCEPTION_H
+
+#include <libpwrutils/exception.h>
+
+namespace Wccl {
+
+/**
+ * Base class for all Wccl errorss. Derives from
+ * @c std::runtime_error. Call member function @c what to get a
+ * human-readable message associated with the error.
+ */
+class WcclError : public PwrNlp::PwrNlpError
+{
+public:
+	/**
+	 * Instantiate a WcclError instance with the given message.
+	 * @param what The message to associate with this error.
+	 */
+	WcclError(const std::string &what);
+
+	~WcclError() throw();
+
+	/// PwrNlpError override
+	std::string scope() const;
+};
+
+class FileNotFound : public WcclError
+{
+public:
+	FileNotFound(const std::string& filename, const std::string& paths,
+			const std::string& where);
+
+	~FileNotFound() throw();
+
+	std::string info() const;
+
+	std::string filename, paths, where;
+};
+
+} /* end ns Wccl */
+
+#endif // LIBWCCL_EXCEPTION_H
-- 
GitLab