diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt index e8fcba589d01d5495cf50d3dad7be4d3df628ff5..fd867ce03c9f50ae325d982ee4edfcec3057574b 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 0000000000000000000000000000000000000000..46c5cc1b7cdbe7e3b097cfc7fb364ce58d9c6756 --- /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 0000000000000000000000000000000000000000..2d52855993d57fc2233966899beac2a3cfae6a79 --- /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