1 use super::ErrorFormat; 2 3 use std::format; 4 use std::string::String; 5 6 #[derive(Debug)] 7 pub enum RuntimeErrorType { 8 //启动失败 9 ExecFailed, 10 11 // 文件相关错误 12 FileNotFound, 13 FileAccessDenied, 14 InvalidFileFormat, 15 16 // 循环依赖 17 CircularDependency, 18 19 // 转型错误 20 DowncastError, 21 22 // 网络相关错误 23 ConnectionError, 24 Timeout, 25 26 // 数据库相关错误 27 DatabaseError, 28 QueryError, 29 30 // 并发相关错误 31 Deadlock, 32 ThreadPanicked, 33 34 // 配置相关错误 35 ConfigError, 36 InvalidParameter, 37 38 // 其他通用错误 39 OutOfMemory, 40 InvalidInput, 41 UnsupportedOperation, 42 43 // 自定义错误 44 Custom(String), 45 } 46 47 pub struct RuntimeError(RuntimeErrorType); 48 49 impl RuntimeError { 50 pub fn new(error_type: RuntimeErrorType) -> Self { 51 return RuntimeError(error_type); 52 } 53 } 54 55 impl ErrorFormat for RuntimeError { 56 fn error_format(&self) -> String { 57 format!("Runtime Error!,Error Type: {:?}", self.0) 58 } 59 } 60