Przeglądaj źródła

refactor & feat: 整理异常

SongZihuan 3 lat temu
rodzic
commit
bc6823891e

+ 8 - 4
include/core/core-exception.h

@@ -1,12 +1,16 @@
 #ifndef AFUN_CORE_EXCEPTION_H
 #define AFUN_CORE_EXCEPTION_H
-#include "iostream"
+#include "aFuntool.h"
 
 namespace aFuncore {
-    class EnvironmentDestructException : public std::exception {
-        constexpr static const char *message = "Environment Destruct Error";
+    class aFuncoreException : public aFuntool::aFunException {
     public:
-        inline virtual const char *what();
+        inline explicit aFuncoreException(const std::string &msg);
+    };
+
+    class EnvironmentDestructException : public aFuncoreException {
+    public:
+        inline EnvironmentDestructException();
     };
 
 }

+ 6 - 2
include/core/core-exception.inline.h

@@ -3,8 +3,12 @@
 #include "core-exception.h"
 
 namespace aFuncore {
-    inline const char *EnvironmentDestructException::what() {
-        return message;
+    inline aFuncoreException::aFuncoreException(const std::string &msg) : aFunException{msg} {
+
+    }
+
+    inline EnvironmentDestructException::EnvironmentDestructException() : aFuncoreException("Environment Destruct Error") {
+
     }
 }
 

+ 19 - 9
include/tool/tool-exception.h

@@ -3,26 +3,36 @@
 #include "tool.h"
 
 namespace aFuntool {
-    class FileOpenException : public std::exception {
+    class aFunException : public std::exception {
         std::string message;
     public:
-        inline explicit FileOpenException(const FilePath &file);
+        inline explicit aFunException(std::string msg);
         inline virtual const char *what();
     };
 
-    class RegexException : public std::exception
-    {
-        std::string message;
+    class aFuntoolException : public aFunException {
+    public:
+        inline explicit aFuntoolException(const std::string &msg);
+    };
+
+    class FileOpenException : public aFuntoolException {
+    public:
+        inline explicit FileOpenException(const FilePath &file);
+    };
+
+    class RegexException : public aFuntoolException {
     public:
         inline explicit RegexException(const std::string &msg);
-        inline virtual const char *what();
     };
 
-    class LogFatalError : public std::exception {
-        std::string message;
+    class LogFatalError : public aFuntoolException {
     public:
         inline explicit LogFatalError(const char *msg);
-        inline virtual const char *what();
+    };
+
+    class Exit : public aFuntoolException {
+    public:
+        inline explicit Exit();
     };
 }
 

+ 15 - 11
include/tool/tool-exception.inline.h

@@ -4,28 +4,32 @@
 #include "tool-exception.h"
 
 namespace aFuntool {
-    inline FileOpenException::FileOpenException(const FilePath &file) {
-        this->message = std::string("File cannot open: ") + file;
+    inline aFunException::aFunException(std::string msg) : message{std::move(msg)} {
+
     }
 
-    inline const char *FileOpenException::what() {
+    inline const char *aFunException::what() {
         return message.c_str();
     }
 
-    inline RegexException::RegexException(const std::string &msg) {
-        this->message = "Regex error: " + msg;
+    inline aFuntoolException::aFuntoolException(const std::string &msg) : aFunException{msg} {
+
     }
 
-    inline const char *RegexException::what() {
-        return message.c_str();
+    inline FileOpenException::FileOpenException(const FilePath &file) : aFuntoolException("File cannot open: " + file) {
+
+    }
+
+    inline RegexException::RegexException(const std::string &msg) : aFuntoolException("Regex error: " + msg) {
+
     }
 
-    inline LogFatalError::LogFatalError(const char *msg) {
-        this->message = msg;
+    inline LogFatalError::LogFatalError(const char *msg) : aFuntoolException(msg) {
+
     }
 
-    inline const char *LogFatalError::what() {
-        return message.c_str();
+    inline Exit::Exit() : aFuntoolException("Exit by user") {
+
     }
 }