diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84ecd7c..429c340 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - true \ No newline at end of file diff --git a/exception.go b/exception.go index aa4a8b1..5274b18 100644 --- a/exception.go +++ b/exception.go @@ -7,7 +7,10 @@ // Date *: 2022-06-25 21:04 package exception -import "errors" +import ( + "errors" + "fmt" +) // Exception 异常接口的具体实现 // @@ -100,6 +103,18 @@ func NewFromError(code interface{}, err error) IException { }) } +// NewFromMessage 从 code message 生成exception +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 22:25 2023/2/11 +func NewFromMessage(code interface{}, message string) IException { + if len(message) == 0 { + message = fmt.Sprintf("%v", code) + } + return NewFromError(code, errors.New(message)) +} + // ToError 转换成内置error // // Author : go_developer@163.com<白茶清欢>