File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed
common/src/main/java/org/tron/core/exception
framework/src/test/java/org/tron/core/exception Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .tron .core .exception ;
2+
3+ import lombok .Getter ;
4+
5+ /**
6+ * If a {@link TronError} is thrown, the service will trigger {@link System#exit(int)} by
7+ * {@link Thread#setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler)}.
8+ * NOTE: Do not attempt to catch {@link TronError}.
9+ */
10+ @ Getter
11+ public class TronError extends Error {
12+
13+ private final ErrCode errCode ;
14+
15+ public TronError (String message , ErrCode exitCode ) {
16+ super (message );
17+ this .errCode = exitCode ;
18+ }
19+
20+ public TronError (String message , Throwable cause , ErrCode exitCode ) {
21+ super (message , cause );
22+ this .errCode = exitCode ;
23+ }
24+
25+ public TronError (Throwable cause , ErrCode exitCode ) {
26+ super (cause );
27+ this .errCode = exitCode ;
28+ }
29+
30+ @ Getter
31+ public enum ErrCode {
32+ WITNESS_KEYSTORE_LOAD (-1 ),
33+ CHECKPOINT_VERSION (-1 ),
34+ LEVELDB_INIT (1 ),
35+ ROCKSDB_INIT (1 ),
36+ DB_FLUSH (1 ),
37+ REWARD_VI_CALCULATOR (1 ),
38+ KHAOS_DB_INIT (1 ),
39+ GENESIS_BLOCK_INIT (1 ),
40+ EVENT_SUBSCRIBE_ERROR (1 ),
41+ AUTO_STOP_PARAMS (1 ),
42+ API_SERVER_INIT (1 ),
43+ SOLID_NODE_INIT (0 );
44+
45+ private final int code ;
46+
47+ ErrCode (int code ) {
48+ this .code = code ;
49+ }
50+
51+ @ Override
52+ public String toString () {
53+ return name () + "(" + code + ")" ;
54+ }
55+ }
56+ }
Original file line number Diff line number Diff line change 1+ package org .tron .core .exception ;
2+
3+ import org .junit .Assert ;
4+ import org .junit .Test ;
5+
6+ public class TronErrorTest {
7+
8+ @ Test
9+ public void testTronError () {
10+ TronError tronError = new TronError ("message" , TronError .ErrCode .WITNESS_KEYSTORE_LOAD );
11+ Assert .assertEquals (tronError .getErrCode (), TronError .ErrCode .WITNESS_KEYSTORE_LOAD );
12+ Assert .assertEquals (tronError .getErrCode ().toString (), "WITNESS_KEYSTORE_LOAD(-1)" );
13+ Assert .assertEquals (tronError .getErrCode ().getCode (), -1 );
14+ tronError = new TronError ("message" , new Throwable (), TronError .ErrCode .API_SERVER_INIT );
15+ Assert .assertEquals (tronError .getErrCode (), TronError .ErrCode .API_SERVER_INIT );
16+ tronError = new TronError (new Throwable (), TronError .ErrCode .LEVELDB_INIT );
17+ Assert .assertEquals (tronError .getErrCode (), TronError .ErrCode .LEVELDB_INIT );
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments