Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
f79c6734
Commit
f79c6734
authored
Aug 10, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
0031b938
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
YzgError.java
...til-base/src/main/java/com/yanzuoguang/util/YzgError.java
+108
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/YzgError.java
0 → 100644
View file @
f79c6734
package
com
.
yanzuoguang
.
util
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 系统错误编码
*
* @author 颜佐光
*/
public
class
YzgError
{
/**
* 错误标记
*/
public
static
final
String
TAG
=
"999."
;
/**
* 错误缓存消息
*/
private
static
Map
<
String
,
String
>
ErrorCode
=
new
HashMap
<>();
private
static
void
init
()
{
add
(
"001"
,
""
);
}
private
static
void
initTemp
()
{
}
public
static
void
add
(
String
code
,
String
message
)
{
ErrorCode
.
put
(
code
,
message
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
throwException
(
String
code
,
Object
...
args
)
{
throw
getException
(
null
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
throwException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
throw
getException
(
ex
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
getException
(
String
code
,
Object
...
args
)
{
return
getException
(
null
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
getException
(
Exception
ex
,
String
code
,
Object
...
args
)
{
return
getException
(
ErrorCode
,
TAG
,
ex
,
code
,
args
);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public
static
CodeException
getException
(
Map
<
String
,
String
>
ErrorCode
,
String
tag
,
Exception
ex
,
String
code
,
Object
...
args
)
{
String
message
=
ErrorCode
.
get
(
code
);
if
(
StringHelper
.
isEmpty
(
message
))
{
message
=
"未知错误"
+
JsonHelper
.
serialize
(
args
);
}
else
{
try
{
message
=
String
.
format
(
message
,
args
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
if
(
ex
!=
null
)
{
return
new
CodeException
(
tag
+
code
,
message
,
ex
);
}
else
{
return
new
CodeException
(
tag
+
code
,
message
);
}
}
static
{
init
();
initTemp
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment