cpp_photon/src/exceptions.cpp

111 lines
3.1 KiB
C++
Raw Normal View History

//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: exceptions.cpp,v 1.6 2005/02/27 05:52:00 cozman Exp $
2005-02-13 22:12:02 +00:00
#include "exceptions.hpp"
namespace photon
{
2005-02-07 01:48:25 +00:00
Throwable::Throwable(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
description_(description), file_(file), line_(line)
{}
Throwable::~Throwable() throw()
{}
std::string Throwable::what() const throw()
{
2005-01-31 15:44:38 +00:00
std::ostringstream ss;
ss << description_;
if(!file_.empty())
{
ss << " (" << file_ << ":" << line_ << ")";
}
return ss.str();
}
std::ostream& operator<<(std::ostream& os, const Throwable& rhs)
{
return os << rhs.what();
}
//exceptions//
2005-02-07 01:48:25 +00:00
Exception::Exception(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Throwable(description,file,line) {}
std::string Exception::what() const throw()
{
return "General exception occured: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
ArgumentException::ArgumentException(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Exception(description,file,line) {}
std::string ArgumentException::what() const throw()
{
return "Invalid argument exception occured: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
PreconditionException::PreconditionException(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Exception(description,file,line) {}
std::string PreconditionException::what() const throw()
{
return "Precondition exception occured: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
RangeException::RangeException(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Exception(description,file,line) {}
std::string RangeException::what() const throw()
{
return "Out-of-range exception: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
ResourceException::ResourceException(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Exception(description,file,line) {}
std::string ResourceException::what() const throw()
{
return "Resource exception: " + Throwable::what();
}
//errors//
2005-02-07 01:48:25 +00:00
Error::Error(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Throwable(description,file,line) {}
std::string Error::what() const throw()
{
return "General error occured: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
MemoryError::MemoryError(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Error(description,file,line) {}
std::string MemoryError::what() const throw()
{
return "Memory error occured: " + Throwable::what();
}
2005-02-07 01:48:25 +00:00
APIError::APIError(const std::string& description,
const std::string& file, uint line) throw() :
2005-01-31 15:44:38 +00:00
Error(description,file,line) {}
std::string APIError::what() const throw()
{
return "Error occured within another library: " + Throwable::what();
}
}