dfhack/library/include/Error.h

382 lines
12 KiB
C

2010-02-27 17:13:34 -07:00
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
2010-02-27 17:13:34 -07:00
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#pragma once
2010-02-27 17:13:34 -07:00
#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED
2011-12-31 04:48:42 -07:00
#include "Export.h"
#include "Pragma.h"
2010-02-27 17:13:34 -07:00
#include <string>
#include <sstream>
2010-02-27 17:13:34 -07:00
#include <exception>
namespace DFHack
{
namespace Error
{
/*
* our wrapper for the C++ exception. used to differentiate
* the whole array of DFHack exceptions from the rest
*/
class DFHACK_EXPORT All : public std::exception{};
2010-11-07 16:10:59 -07:00
class DFHACK_EXPORT AllMemdef : public All{};
class DFHACK_EXPORT NoProcess : public All
2010-02-27 17:13:34 -07:00
{
public:
virtual const char* what() const throw()
{
return "couldn't find a suitable process";
}
};
class DFHACK_EXPORT CantAttach : public All
2010-02-27 17:13:34 -07:00
{
public:
virtual const char* what() const throw()
{
return "couldn't attach to process";
}
};
2010-02-27 18:37:05 -07:00
class DFHACK_EXPORT NoMapLoaded : public All
2010-02-27 18:37:05 -07:00
{
public:
virtual const char* what() const throw()
{
return "no map has been loaded in the dwarf fortress process";
}
};
class DFHACK_EXPORT BadMapDimensions : public All
2010-02-27 18:37:05 -07:00
{
public:
BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {}
const uint32_t x;
const uint32_t y;
virtual const char* what() const throw()
{
return "both x and y needs to be between 0 and 48";
}
};
// a call to DFHack::mem_info::get* failed
2010-11-07 16:10:59 -07:00
class DFHACK_EXPORT MissingMemoryDefinition : public AllMemdef
{
public:
MissingMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key)
2010-04-23 10:51:54 -06:00
{
std::stringstream s;
s << "memory object not declared: type=" << type << " key=" << key;
2010-04-23 10:51:54 -06:00
full = s.str();
}
// Used by functios using integer keys, such as getTrait
MissingMemoryDefinition(const char* _type, uint32_t _key) : type(_type)
{
2010-04-23 10:51:54 -06:00
std::stringstream s1;
s1 << _key;
key = s1.str();
std::stringstream s;
s << "memory object not declared: type=" << type << " key=" << key;
2010-04-23 10:51:54 -06:00
full = s.str();
}
2010-02-28 17:21:54 -07:00
virtual ~MissingMemoryDefinition() throw(){};
std::string full;
const std::string type;
std::string key;
virtual const char* what() const throw()
{
return full.c_str();
}
};
// a call to DFHack::mem_info::get* failed
2010-11-07 16:10:59 -07:00
class DFHACK_EXPORT UnsetMemoryDefinition : public AllMemdef
{
public:
UnsetMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key)
{
std::stringstream s;
s << "memory object not set: type " << type << " key " << key;
full = s.str();
}
// Used by functios using integer keys, such as getTrait
UnsetMemoryDefinition(const char* _type, uint32_t _key) : type(_type)
{
std::stringstream s1;
s1 << _key;
key = s1.str();
std::stringstream s;
s << "memory object not set: type " << type << " key " << key;
full = s.str();
}
virtual ~UnsetMemoryDefinition() throw(){};
2010-04-23 10:51:54 -06:00
std::string full;
const std::string type;
std::string key;
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-02-28 13:44:14 -07:00
}
};
2010-11-07 16:10:59 -07:00
// a call to DFHack::mem_info::get* failed
class DFHACK_EXPORT InvalidMemoryDefinition : public AllMemdef
{
public:
InvalidMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key)
{
std::stringstream s;
s << "memory object is INVALID: type " << type << " key " << key;
full = s.str();
}
// Used by functios using integer keys, such as getTrait
InvalidMemoryDefinition(const char* _type, uint32_t _key) : type(_type)
{
std::stringstream s1;
s1 << _key;
key = s1.str();
std::stringstream s;
s << "memory object is INVALID: type " << type << " key " << key;
full = s.str();
}
virtual ~InvalidMemoryDefinition() throw(){};
std::string full;
const std::string type;
std::string key;
virtual const char* what() const throw()
{
return full.c_str();
}
};
// Syntax errors and whatnot, the xml can't be read
class DFHACK_EXPORT MemoryXmlParse : public All
2010-02-28 13:44:14 -07:00
{
public:
2010-04-23 10:51:54 -06:00
MemoryXmlParse(const char* _desc, int _id, int _row, int _col)
:desc(_desc), id(_id), row(_row), col(_col)
{
std::stringstream s;
s << "error " << id << ": " << desc << ", at row " << row << " col " << col;
full = s.str();
}
2010-11-07 16:10:59 -07:00
2010-04-23 10:51:54 -06:00
std::string full;
2010-02-28 13:44:14 -07:00
const std::string desc;
const int id;
const int row;
const int col;
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlParse() throw(){};
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-02-28 13:44:14 -07:00
}
};
class DFHACK_EXPORT MemoryXmlBadAttribute : public All
2010-02-28 13:44:14 -07:00
{
public:
2010-04-23 10:51:54 -06:00
MemoryXmlBadAttribute(const char* _attr) : attr(_attr)
{
std::stringstream s;
s << "attribute is either missing or invalid: " << attr;
full = s.str();
}
std::string full;
2010-02-28 13:44:14 -07:00
std::string attr;
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlBadAttribute() throw(){};
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-02-28 13:44:14 -07:00
}
};
class DFHACK_EXPORT MemoryXmlNoRoot : public All
2010-02-28 13:44:14 -07:00
{
public:
MemoryXmlNoRoot() {}
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlNoRoot() throw(){};
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
return "no pElem found";
}
};
class DFHACK_EXPORT MemoryXmlNoDFExtractor : public All
2010-02-28 13:44:14 -07:00
{
public:
2010-04-23 10:51:54 -06:00
MemoryXmlNoDFExtractor(const char* _name) : name(_name)
{
std::stringstream s;
s << "DFExtractor != " << name;
full = s.str();
}
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlNoDFExtractor() throw(){};
2010-02-28 13:44:14 -07:00
std::string name;
2010-04-23 10:51:54 -06:00
std::string full;
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-02-28 13:44:14 -07:00
}
};
class DFHACK_EXPORT MemoryXmlUnderspecifiedEntry : public All
2010-02-28 13:44:14 -07:00
{
public:
2010-04-23 10:51:54 -06:00
MemoryXmlUnderspecifiedEntry(const char * _where) : where(_where)
{
std::stringstream s;
s << "underspecified MemInfo entry, each entry needs to set both the name attribute and have a value. parent: " << where;
full = s.str();
}
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlUnderspecifiedEntry() throw(){};
std::string where;
2010-04-23 10:51:54 -06:00
std::string full;
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-02-28 13:44:14 -07:00
}
};
class DFHACK_EXPORT MemoryXmlUnknownType : public All
2010-02-28 13:44:14 -07:00
{
public:
2010-04-23 10:51:54 -06:00
MemoryXmlUnknownType(const char* _type) : type(_type)
{
std::stringstream s;
s << "unknown MemInfo type: " << type;
full = s.str();
}
2010-02-28 17:21:54 -07:00
virtual ~MemoryXmlUnknownType() throw(){};
2010-02-28 13:44:14 -07:00
std::string type;
2010-04-23 10:51:54 -06:00
std::string full;
2010-02-28 13:44:14 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
}
};
2010-03-08 19:30:22 -07:00
class DFHACK_EXPORT SHMServerDisappeared : public All
2010-03-08 19:30:22 -07:00
{
public:
SHMServerDisappeared(){}
virtual ~SHMServerDisappeared() throw(){};
virtual const char* what() const throw()
{
return "The server process has disappeared";
}
};
class DFHACK_EXPORT SHMLockingError : public All
2010-03-11 16:13:50 -07:00
{
public:
2010-04-23 10:51:54 -06:00
SHMLockingError(const char* _type) : type(_type)
{
std::stringstream s;
s << "SHM locking error: " << type;
full = s.str();
}
2010-03-11 16:13:50 -07:00
virtual ~SHMLockingError() throw(){};
std::string type;
2010-04-23 10:51:54 -06:00
std::string full;
2010-03-11 16:13:50 -07:00
virtual const char* what() const throw()
{
2010-04-23 10:51:54 -06:00
return full.c_str();
2010-03-11 16:13:50 -07:00
}
};
class DFHACK_EXPORT MemoryAccessDenied : public All
2010-03-11 16:13:50 -07:00
{
public:
2011-03-27 18:09:13 -06:00
std::string descr;
MemoryAccessDenied(uint64_t address)
{
std::stringstream s;
s << "Invalid memory access @0x" << std::hex << address;
descr = s.str();
}
virtual ~MemoryAccessDenied() throw(){};
2010-03-11 16:13:50 -07:00
virtual const char* what() const throw()
{
2011-03-27 18:09:13 -06:00
return descr.c_str();
2010-03-11 16:13:50 -07:00
}
};
class DFHACK_EXPORT SHMVersionMismatch : public All
2010-03-11 16:13:50 -07:00
{
public:
SHMVersionMismatch() {}
virtual ~SHMVersionMismatch() throw(){};
virtual const char* what() const throw()
{
return "SHM VERSION MISMATCH";
}
};
class DFHACK_EXPORT SHMAttachFailure : public All
2010-03-11 16:13:50 -07:00
{
public:
SHMAttachFailure() {}
virtual ~SHMAttachFailure() throw(){};
virtual const char* what() const throw()
{
return "SHM ATTACH FAILURE";
}
};
class DFHACK_EXPORT ModuleNotInitialized : public All
{
public:
ModuleNotInitialized() {}
virtual ~ModuleNotInitialized() throw(){};
virtual const char* what() const throw()
{
return "Programmer error: module not initialized!";
}
};
2010-03-11 16:13:50 -07:00
2010-02-27 17:13:34 -07:00
}
}
#endif // ERROR_H_INCLUDED