cpp_photon/src/exceptions.cpp

106 lines
3.2 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:
2005-02-16 06:58:05 +00:00
// $Id: exceptions.cpp,v 1.5 2005/02/16 06:58:26 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::getDesc() const throw()
{
2005-01-31 15:44:38 +00:00
std::ostringstream ss;
ss << description_;
if(!file_.empty())
{
ss << " (" << file_ << ":" << line_ << ")";
}
return ss.str();
}
//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::ostream& operator<<(std::ostream& os, const Exception& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "General exception occured: " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const ArgumentException& rhs)
{
return os << "Invalid argument exception occured. " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const PreconditionException& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "Precondition exception occured: " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const RangeException& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "Out-of-range exception: " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const ResourceException& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "Resource exception: " << rhs.getDesc();
}
//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::ostream& operator<<(std::ostream& os, const Error& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "General error occured: " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const MemoryError& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "Memory error occured: " << rhs.getDesc();
}
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::ostream& operator<<(std::ostream& os, const APIError& rhs)
{
2005-01-31 15:44:38 +00:00
return os << "Error occured within another library: " << rhs.getDesc();
}
}