⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exception.h

📁 大学时用c++做的计算器
💻 H
字号:
#ifndef EXCEPTION_H
#define EXCEPTION_H

#include <string>

// base

class Exception {
public:
    virtual const char* debugPrint() = 0;
    virtual ~Exception() {}
};

// category

class MathException : public Exception {
public:
    virtual const char* debugPrint() = 0;
};

class SyntaxException : public Exception {
public:
    virtual const char* debugPrint() = 0;
};

// concrete exceptions

// MathException

class TooLarge : public MathException {
public:
	const char* debugPrint() { return "number exceed limit"; }
};

class ZeroDivide : public MathException {
public:
    const char* debugPrint() { return "divide by 0"; }
};

class PowerError : public MathException {
public:
    const char* debugPrint() { return "power error"; }
};

class AsinError : public MathException {
public:
    const char* debugPrint() { return "asin domain [-1, 1]"; }
};

class AcosError : public MathException {
public:
    const char* debugPrint() { return "acos domain [-1, 1]"; }
};

class TanError : public MathException {
public:
    const char* debugPrint() { return "tan not defined at the value"; }
};

class AcoshError : public MathException {
public:
    const char* debugPrint() { return "acosh domain [1, infinite)"; }
};

class AtanhError : public MathException {
public:
    const char* debugPrint() { return "atanh domain (-1, 1)"; }
};

class LogError : public MathException {
public:
    const char* debugPrint() { return "log domain (0, infinite)"; }
};

class LnError : public MathException {
public:
    const char* debugPrint() { return "ln domain (0, infinite)"; }
};

class SqrtError : public MathException {
public:
    const char* debugPrint() { return "negative values have no square roots"; }
};


// SyntaxException

class InvalidAssignment : public SyntaxException {
public:
    const char* debugPrint() { return "can't reassign value to predefined identifier"; }
};

class LeftParenMismatch : public SyntaxException {
public:
    const char* debugPrint() { return "parenthesises mismatch, ( missing"; }
};

class RightParenMismatch : public SyntaxException {
public:
    const char* debugPrint() { return "parenthesises mismatch, ) missing"; }
};

class PrimaryMissing : public SyntaxException {
public:
    const char* debugPrint() { return "primary missing"; }
};

class BadToken : public SyntaxException {
public:
    const char* debugPrint() { return "bad token"; }
};

class ParenMissing : public SyntaxException {
public:
    explicit ParenMissing(const char* function) : __info(function) {}

    const char* debugPrint()
    {
        __info = "( missing after " + __info;
        return __info.c_str();
    }
private:
    std::string __info;
};

#endif  // EXCEPTION_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -