major update to way Exceptions are written, now use std::exception
This commit is contained in:
parent
7471a2b4e6
commit
2d2b0fcece
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// Version:
|
||||||
// $Id: exceptions.hpp,v 1.2 2005/02/16 06:58:05 cozman Exp $
|
// $Id: exceptions.hpp,v 1.3 2005/02/27 05:51:59 cozman Exp $
|
||||||
|
|
||||||
#ifndef PHOTON_EXCEPTIONS_HPP
|
#ifndef PHOTON_EXCEPTIONS_HPP
|
||||||
#define PHOTON_EXCEPTIONS_HPP
|
#define PHOTON_EXCEPTIONS_HPP
|
||||||
@ -48,7 +48,8 @@ public:
|
|||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
virtual ~Throwable() throw()=0;
|
virtual ~Throwable() throw()=0;
|
||||||
|
|
||||||
std::string getDesc() const throw();
|
std::string virtual what() const throw();
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Throwable& rhs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string description_;
|
std::string description_;
|
||||||
@ -61,12 +62,9 @@ private:
|
|||||||
// it, and it inherits from <Throwable>.
|
// it, and it inherits from <Throwable>.
|
||||||
// Exception should be used for hard to classify exceptions.
|
// Exception should be used for hard to classify exceptions.
|
||||||
//
|
//
|
||||||
// Exception's children should be used when a problem occurs which is
|
// Exception and children should be used when a problem occurs which is
|
||||||
// recoverable.
|
// recoverable.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// See Also:
|
// See Also:
|
||||||
// <Error>
|
// <Error>
|
||||||
//
|
//
|
||||||
@ -84,17 +82,13 @@ public:
|
|||||||
Exception(const std::string& description = std::string(),
|
Exception(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const Exception& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: ArgumentException
|
// Class: ArgumentException
|
||||||
// ArgumentException should be thrown when an argument is passed to a function
|
// ArgumentException should be thrown when an argument is passed to a function
|
||||||
// that is invalid.
|
// that is invalid.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Exception>
|
// <Exception>
|
||||||
class ArgumentException : public Exception
|
class ArgumentException : public Exception
|
||||||
@ -103,16 +97,12 @@ public:
|
|||||||
ArgumentException(const std::string& description = std::string(),
|
ArgumentException(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const ArgumentException& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: PreconditionException
|
// Class: PreconditionException
|
||||||
// PreconditionException should be thrown when a precondition is not met.
|
// PreconditionException should be thrown when a precondition is not met.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Exception>
|
// <Exception>
|
||||||
class PreconditionException : public Exception
|
class PreconditionException : public Exception
|
||||||
@ -121,61 +111,47 @@ public:
|
|||||||
PreconditionException(const std::string& description = std::string(),
|
PreconditionException(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const PreconditionException& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: RangeException
|
// Class: RangeException
|
||||||
// RangeException should be thrown if something (such as an array bound) is out
|
// RangeException should be thrown if something (such as an array bound) is out
|
||||||
// of bounds.
|
// of bounds.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Exception>
|
// <Exception>
|
||||||
class RangeException : public Exception
|
class RangeException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RangeException() throw();
|
|
||||||
RangeException(const std::string& description = std::string(),
|
RangeException(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const RangeException& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: ResourceException
|
// Class: ResourceException
|
||||||
// ResourceException should be thrown if there is a problem accessing a
|
// ResourceException should be thrown if there is a problem accessing a
|
||||||
// resource.
|
// resource.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Exception>
|
// <Exception>
|
||||||
class ResourceException : public Exception
|
class ResourceException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ResourceException() throw();
|
|
||||||
ResourceException(const std::string& description = std::string(),
|
ResourceException(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const ResourceException& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: Error
|
// Class: Error
|
||||||
// GeneralError is the base error class, all errors inherit from it, and it
|
// Error is the base error class, all errors inherit from it, and it inherits
|
||||||
// inherits from <Throwable>.
|
// from <Throwable>.
|
||||||
// Error should be used for hard to classify errors.
|
// Error should be used for hard to classify errors.
|
||||||
//
|
//
|
||||||
// Errors should be used when a problem occurs which is difficult to just
|
// Errors should be used when a problem occurs which is difficult to just
|
||||||
// ignore, usually more severe than exceptions.
|
// ignore, usually more severe than exceptions.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// See Also:
|
// See Also:
|
||||||
// <Exception>
|
// <Exception>
|
||||||
//
|
//
|
||||||
@ -183,56 +159,44 @@ public:
|
|||||||
// <Throwable>
|
// <Throwable>
|
||||||
//
|
//
|
||||||
// Children:
|
// Children:
|
||||||
// <MemoryError>
|
|
||||||
// <APIError>
|
// <APIError>
|
||||||
|
// <MemoryError>
|
||||||
class Error : public Throwable
|
class Error : public Throwable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Error() throw();
|
|
||||||
Error(const std::string&description = std::string(),
|
Error(const std::string&description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const Error& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: MemoryError
|
// Class: MemoryError
|
||||||
// MemoryError should be thrown if there is an error allocating memory.
|
// MemoryError should be thrown if an error occurs while allocating memory.
|
||||||
//
|
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
//
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Error>
|
// <Error>
|
||||||
class MemoryError : public Error
|
class MemoryError : public Error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MemoryError() throw();
|
|
||||||
MemoryError(const std::string& description = std::string(),
|
MemoryError(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const MemoryError& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class: APIError
|
// Class: APIError
|
||||||
// APIError should be thrown if an error occurs in code which is not part of
|
// APIError should be thrown if an error occurs in code which is not part of
|
||||||
// Photon.
|
// Photon.
|
||||||
//
|
//
|
||||||
// Operators:
|
|
||||||
// ostream&<<
|
|
||||||
//
|
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Error>
|
// <Throwable>
|
||||||
class APIError : public Error
|
class APIError : public Error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
APIError() throw();
|
|
||||||
APIError(const std::string& description = std::string(),
|
APIError(const std::string& description = std::string(),
|
||||||
const std::string& file = std::string(),
|
const std::string& file = std::string(),
|
||||||
uint line=0) throw();
|
uint line=0) throw();
|
||||||
friend std::ostream& operator<<(std::ostream& os,
|
std::string what() const throw();
|
||||||
const APIError& rhs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// Version:
|
||||||
// $Id: exceptions.cpp,v 1.5 2005/02/16 06:58:26 cozman Exp $
|
// $Id: exceptions.cpp,v 1.6 2005/02/27 05:52:00 cozman Exp $
|
||||||
|
|
||||||
|
|
||||||
#include "exceptions.hpp"
|
#include "exceptions.hpp"
|
||||||
@ -22,7 +22,7 @@ Throwable::Throwable(const std::string& description,
|
|||||||
Throwable::~Throwable() throw()
|
Throwable::~Throwable() throw()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Throwable::getDesc() const throw()
|
std::string Throwable::what() const throw()
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
@ -34,46 +34,51 @@ std::string Throwable::getDesc() const throw()
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Throwable& rhs)
|
||||||
|
{
|
||||||
|
return os << rhs.what();
|
||||||
|
}
|
||||||
|
|
||||||
//exceptions//
|
//exceptions//
|
||||||
|
|
||||||
Exception::Exception(const std::string& description,
|
Exception::Exception(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Throwable(description,file,line) {}
|
Throwable(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const Exception& rhs)
|
std::string Exception::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "General exception occured: " << rhs.getDesc();
|
return "General exception occured: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgumentException::ArgumentException(const std::string& description,
|
ArgumentException::ArgumentException(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Exception(description,file,line) {}
|
Exception(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const ArgumentException& rhs)
|
std::string ArgumentException::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Invalid argument exception occured. " << rhs.getDesc();
|
return "Invalid argument exception occured: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
PreconditionException::PreconditionException(const std::string& description,
|
PreconditionException::PreconditionException(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Exception(description,file,line) {}
|
Exception(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const PreconditionException& rhs)
|
std::string PreconditionException::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Precondition exception occured: " << rhs.getDesc();
|
return "Precondition exception occured: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeException::RangeException(const std::string& description,
|
RangeException::RangeException(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Exception(description,file,line) {}
|
Exception(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const RangeException& rhs)
|
std::string RangeException::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Out-of-range exception: " << rhs.getDesc();
|
return "Out-of-range exception: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceException::ResourceException(const std::string& description,
|
ResourceException::ResourceException(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Exception(description,file,line) {}
|
Exception(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const ResourceException& rhs)
|
std::string ResourceException::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Resource exception: " << rhs.getDesc();
|
return "Resource exception: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
//errors//
|
//errors//
|
||||||
@ -81,25 +86,25 @@ std::ostream& operator<<(std::ostream& os, const ResourceException& rhs)
|
|||||||
Error::Error(const std::string& description,
|
Error::Error(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Throwable(description,file,line) {}
|
Throwable(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const Error& rhs)
|
std::string Error::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "General error occured: " << rhs.getDesc();
|
return "General error occured: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryError::MemoryError(const std::string& description,
|
MemoryError::MemoryError(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Error(description,file,line) {}
|
Error(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const MemoryError& rhs)
|
std::string MemoryError::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Memory error occured: " << rhs.getDesc();
|
return "Memory error occured: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
APIError::APIError(const std::string& description,
|
APIError::APIError(const std::string& description,
|
||||||
const std::string& file, uint line) throw() :
|
const std::string& file, uint line) throw() :
|
||||||
Error(description,file,line) {}
|
Error(description,file,line) {}
|
||||||
std::ostream& operator<<(std::ostream& os, const APIError& rhs)
|
std::string APIError::what() const throw()
|
||||||
{
|
{
|
||||||
return os << "Error occured within another library: " << rhs.getDesc();
|
return "Error occured within another library: " + Throwable::what();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user