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