108 lines
4.2 KiB
C++
108 lines
4.2 KiB
C++
#ifndef EXCEPTION_H
|
|
#define EXCEPTION_H
|
|
|
|
#include "Object.h"
|
|
|
|
namespace Kylin {
|
|
|
|
#define THROW_EXCEPTION(e, m) (throw e(__FILE__, __LINE__, m))
|
|
|
|
class Exception : public Object {
|
|
public:
|
|
Exception(const char *message);
|
|
Exception(const char *file, int line);
|
|
Exception(const char *file, int line, const char *message);
|
|
Exception(const Exception &e);
|
|
Exception &operator=(const Exception &e);
|
|
virtual const char *message() const;
|
|
virtual const char *location() const;
|
|
virtual ~Exception() = 0;
|
|
|
|
protected:
|
|
void init(const char *file, int line, const char *message);
|
|
char *m_message = nullptr;
|
|
char *m_location = nullptr;
|
|
};
|
|
|
|
class ArithmeticException : public Exception {
|
|
public:
|
|
ArithmeticException(const char *message) : Exception(message) {}
|
|
ArithmeticException(const char *file, int line) : Exception(file, line) {}
|
|
ArithmeticException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
ArithmeticException(const ArithmeticException &e) : Exception(e) {}
|
|
ArithmeticException &operator=(const ArithmeticException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~ArithmeticException();
|
|
};
|
|
|
|
class NullPointerException : public Exception {
|
|
public:
|
|
NullPointerException(const char *message) : Exception(message) {}
|
|
NullPointerException(const char *file, int line) : Exception(file, line) {}
|
|
NullPointerException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
NullPointerException(const NullPointerException &e) : Exception(e) {}
|
|
NullPointerException &operator=(const NullPointerException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~NullPointerException();
|
|
};
|
|
|
|
class IndexOutOfBoundsException : public Exception {
|
|
public:
|
|
IndexOutOfBoundsException(const char *message) : Exception(message) {}
|
|
IndexOutOfBoundsException(const char *file, int line) : Exception(file, line) {}
|
|
IndexOutOfBoundsException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
IndexOutOfBoundsException(const IndexOutOfBoundsException &e) : Exception(e) {}
|
|
IndexOutOfBoundsException &operator=(const IndexOutOfBoundsException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~IndexOutOfBoundsException();
|
|
};
|
|
|
|
class NoEnoughMemoryException : public Exception {
|
|
public:
|
|
NoEnoughMemoryException(const char *message) : Exception(message) {}
|
|
NoEnoughMemoryException(const char *file, int line) : Exception(file, line) {}
|
|
NoEnoughMemoryException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
NoEnoughMemoryException(const NoEnoughMemoryException &e) : Exception(e) {}
|
|
NoEnoughMemoryException &operator=(const NoEnoughMemoryException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~NoEnoughMemoryException();
|
|
};
|
|
|
|
class InvalidParameterException : public Exception {
|
|
public:
|
|
InvalidParameterException(const char *message) : Exception(message) {}
|
|
InvalidParameterException(const char *file, int line) : Exception(file, line) {}
|
|
InvalidParameterException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
InvalidParameterException(const InvalidParameterException &e) : Exception(e) {}
|
|
InvalidParameterException &operator=(const InvalidParameterException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~InvalidParameterException();
|
|
};
|
|
|
|
class InvalidOperationException : public Exception {
|
|
public:
|
|
InvalidOperationException(const char *message) : Exception(message) {}
|
|
InvalidOperationException(const char *file, int line) : Exception(file, line) {}
|
|
InvalidOperationException(const char *file, int line, const char *message) : Exception(file, line, message) {}
|
|
InvalidOperationException(const InvalidOperationException &e) : Exception(e) {}
|
|
InvalidOperationException &operator=(const InvalidOperationException &e) {
|
|
Exception::operator=(e);
|
|
return *this;
|
|
}
|
|
~InvalidOperationException();
|
|
};
|
|
|
|
} // namespace Kylin
|
|
|
|
#endif // EXCEPTION_H
|