Logo Search packages:      
Sourcecode: jaula version File versions

jaula_exception.cc

/*
 * jaula_exception.cc : JSON Analysis User Library Acronym
 * Error handling definitions
 *
 * Copyright (C) 2007, 2008 Kombo Morongo <morongo666@gmail.com>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * svn info:
 * $Author: morongo $
 * $HeadURL: https://jaula.svn.sourceforge.net/svnroot/jaula/tags/jaula-1.3.0-1/jaula/jaula_exception.cc $
 * $Id: jaula_exception.cc 38 2008-07-05 12:00:37Z morongo $
 * $Revision: 38 $
 */

extern "C"
{
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
}


#include <jaula/jaula_exception.h>

namespace JAULA
{                                // namespace JAULA

00042   Exception::Exception(ExCode code
    , std::string const &detail
    , std::string const &action
    , std::string const &origin)
    : code_(code)
    , detail_(detail)
    , action_(action)
    , origin_(origin)
    {}

00052   Exception::Exception(Exception const &orig)
    : code_(orig.getCode())
    , detail_(orig.getDetail())
    , action_(orig.getAction())
    , origin_(orig.getOrigin())
    {}

00059   Exception::~Exception()
    {}

00062   Exception::ExCode Exception::getCode(void) const
  {
    return code_;
  }

00067   std::string const &Exception::getDetail(void) const
  {
    return detail_;
  }

00072   std::string const &Exception::getAction(void) const
  {
    return action_;
  }

00077   std::string const &Exception::getOrigin(void) const
  {
    return origin_;
  }

00082   void Exception::display(std::ostream &ostr) const
  {
    ostr << "JAULA Exception(";
    switch(code_)
    {
      case NO_ERROR :
        ostr << "No Error";
        break;

      case BAD_DATA_TYPE :
        ostr << "Bad Data Type";
        break;

      case NAME_DUPLICATED :
        ostr << "Property name already exists";
        break;

      case LEXAN_ERROR :
        ostr << "Error detected during lexical analysis";
        break;

      case SYNTAX_ERROR :
        ostr << "Error detected during syntax analysis";
        break;

      default :
        ostr << "Unknown Error";
        break;

    }
    ostr << ")";

    if (!detail_.empty())
      ostr << " : " << detail_ << ".";

    if (!action_.empty())
      ostr << " Exception arose while " << action_ << ".";

    if (!origin_.empty())
      ostr << " Exception detected running " << origin_ << ".";
  }

00124   void Exception::setCode(ExCode code)
  {
    code_ = code;
  }

00129   void Exception::setDetail(std::string const &detail)
  {
    detail_ = detail;
  }

00134   void Exception::setAction(std::string const &action)
  {
    action_ = action;
  }

00139   void Exception::setOrigin(std::string const &origin)
  {
    origin_ = origin;
  }

00144   void Exception::addOrigin(std::string const &origin)
  {
    if (origin_.empty())
      origin_ = origin;
    else
    {
      origin_ += " invoked by ";
      origin_ += origin;
    }
  }

00155   Exception &Exception::operator=(Exception const &orig)
  {
    if (this == &orig)
      return *this;

    code_ = orig.getCode();
    detail_ = orig.getDetail();
    action_ = orig.getAction();
    origin_ = orig.getOrigin();

    return *this;
  }

}                                // namespace JAULA


00171 std::ostream &operator<<(std::ostream &ostr, JAULA::Exception const &ex)
{
  ex.display(ostr);
  return ostr;
}


// EOF $Id: jaula_exception.cc 38 2008-07-05 12:00:37Z morongo $

Generated by  Doxygen 1.6.0   Back to index