From 1ddfbad7dab05aa0ecb29fbff6720826104c0e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 11 Feb 2023 22:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=AE=9E=E4=BE=8B=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 45 +++++---------------------------------------- exception.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 41 deletions(-) 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<白茶清欢>