#ifndef _OL_EXCEPTIONS_H
#define _OL_EXCEPTIONS_H
#include "hfstol-stdafx.h"
#include <string>
#include <sstream>
#include <cstring>
namespace hfst_ospell
{
struct OspellException
{
std::string name;
std::string file;
size_t line;
OspellException(void) {}
OspellException(const std::string &name,const std::string &file,size_t line):
name(name),
file(file),
line(line)
{}
std::string operator() (void) const
{
std::ostringstream o;
o << "Exception: "<< name << " in file: "
<< file << " on line: " << line;
return o.str();
}
const char* what()
{
std::ostringstream o;
o << file << ":" << line << ":" << name;
return strdup(o.str().c_str());
}
};
#define HFSTOSPELL_THROW(E) throw E(#E,__FILE__,__LINE__)
#define HFSTOSPELL_THROW_MESSAGE(E,M) throw E(std::string(#E)+": "+std::string(M)\
,__FILE__,__LINE__)
#define HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(CHILD) \
struct CHILD : public OspellException \
{ CHILD(const std::string &name,const std::string &file,size_t line):\
OspellException(name,file,line) {}}
#define HFST_CATCH(E) \
catch (const E &e) \
{ \
std::cerr << e.file << ", line " << e.line << ": " << \
e() << std::endl; \
}
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(HeaderParsingException);
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(AlphabetParsingException);
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(IndexTableReadingException);
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(TransitionTableReadingException);
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(UnweightedSpellerException);
HFSTOSPELL_EXCEPTION_CHILD_DECLARATION(TransducerTypeException);
}
#endif