dlvhex  2.5.0
src/Error.cpp
Go to the documentation of this file.
00001 /* dlvhex -- Answer-Set Programming with external interfaces.
00002  * Copyright (C) 2005-2007 Roman Schindlauer
00003  * Copyright (C) 2006-2015 Thomas Krennwallner
00004  * Copyright (C) 2009-2016 Peter Schüller
00005  * Copyright (C) 2011-2016 Christoph Redl
00006  * Copyright (C) 2015-2016 Tobias Kaminski
00007  * Copyright (C) 2015-2016 Antonius Weinzierl
00008  *
00009  * This file is part of dlvhex.
00010  *
00011  * dlvhex is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU Lesser General Public License as
00013  * published by the Free Software Foundation; either version 2.1 of
00014  * the License, or (at your option) any later version.
00015  *
00016  * dlvhex is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with dlvhex; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00037 #ifdef HAVE_CONFIG_H
00038 #include "config.h"
00039 #endif                           // HAVE_CONFIG_H
00040 
00041 #include "dlvhex2/Error.h"
00042 
00043 #include <sstream>
00044 
00045 DLVHEX_NAMESPACE_BEGIN
00046 
00047 GeneralError::GeneralError(const std::string& msg)
00048 : std::runtime_error(msg)
00049 {
00050 }
00051 
00052 
00053 SyntaxError::SyntaxError(const std::string& msg,
00054 const unsigned l,
00055 const std::string& f)
00056 : GeneralError(msg),
00057 line(l),
00058 file(f)
00059 {
00060 }
00061 
00062 
00063 std::string
00064 SyntaxError::getErrorMsg() const
00065 {
00066     std::ostringstream err;
00067 
00068     err << "Syntax Error";
00069 
00070     if (!file.empty())
00071         err << " in " << file;
00072 
00073     if (line != 0)
00074         err << ", line " << line;
00075 
00076     err << ": " << this->what();
00077 
00078     return err.str();
00079 }
00080 
00081 
00082 void
00083 SyntaxError::setLine(unsigned l)
00084 {
00085     this->line = l;
00086 }
00087 
00088 
00089 void
00090 SyntaxError::setFile(const std::string& f)
00091 {
00092     this->file = f;
00093 }
00094 
00095 
00096 FatalError::FatalError(const std::string& msg)
00097 : GeneralError("Fatal: " + msg)
00098 {
00099 }
00100 
00101 
00102 PluginError::PluginError(const std::string& msg)
00103 : GeneralError(msg)
00104 {
00105 }
00106 
00107 
00108 void
00109 PluginError::setContext(const std::string& c)
00110 {
00111     context = c;
00112 }
00113 
00114 
00115 std::string
00116 PluginError::getErrorMsg() const
00117 {
00118     std::ostringstream err;
00119 
00120     err << "Plugin Error";
00121 
00122     if (!context.empty())
00123         err << " in " << context;
00124 
00125     err << ": " << this->what();
00126 
00127     return err.str();
00128 }
00129 
00130 
00131 DLVHEX_NAMESPACE_END
00132 
00133 
00134 // vim:expandtab:ts=4:sw=4:
00135 // mode: C++
00136 // End: