1
1
package io .github .javaezlib .javaez .backend ;
2
2
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
3
6
/**
4
7
* The backend JavaEZ error system, used for handling internal Java errors.
5
- * @author RedstoneBoy0509
8
+ * @author Red050911
6
9
* @since 1.0
7
10
*/
8
11
public class ErrorSystem {
9
12
13
+ /**
14
+ * The list of classnames allowed to call errors.
15
+ * @since 1.5
16
+ */
17
+ private static final List <String > ACCEPTED_CLASSNAMES = new ArrayList <>();
18
+
19
+ static {
20
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.extensions.Core" );
21
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.extensions.Files" );
22
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.extensions.System" );
23
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.extensions.Threads" );
24
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.backend.BackendVariableContext" );
25
+ ACCEPTED_CLASSNAMES .add ("io.github.javaezlib.javaez.JavaEZ" );
26
+ }
27
+
10
28
/**
11
29
* Sends a JavaEZ error to the console.
12
30
* @param className The name of the erroring class
@@ -15,7 +33,7 @@ public class ErrorSystem {
15
33
* @deprecated This is an internal method, not needing to be used by the user.
16
34
*/
17
35
@ Deprecated
18
- public static void sendError (String className , String message ) {
36
+ private static void sendError (String className , String message ) {
19
37
System .err .println ("[JavaEZ] [Error at class " + className + "] >> " + message );
20
38
}
21
39
@@ -27,8 +45,27 @@ public static void sendError(String className, String message) {
27
45
*/
28
46
@ Deprecated
29
47
public static void handleError (String error ) {
30
- StackTraceElement e = Thread .currentThread ().getStackTrace ()[3 ];
31
- sendError (e .getClassName (), error );
48
+ try {
49
+ StackTraceElement e = Thread .currentThread ().getStackTrace ()[2 ];
50
+ if (ACCEPTED_CLASSNAMES .contains (e .getClassName ())) {
51
+ e = Thread .currentThread ().getStackTrace ()[3 ];
52
+ sendError (e .getClassName (), error );
53
+ } else {
54
+ try {
55
+ StackTraceElement el = Thread .currentThread ().getStackTrace ()[2 ];
56
+ sendError (el .getClassName (), "Sorry, but this class is not meant to be called upon by user classes." );
57
+ } catch (Exception ex2 ) {
58
+ sendError ("[CLASSNAME IRRETRIEVABLE]" , "Sorry, but this class is not meant to be called upon by user classes." );
59
+ }
60
+ }
61
+ } catch (Exception ex ) {
62
+ try {
63
+ StackTraceElement e = Thread .currentThread ().getStackTrace ()[2 ];
64
+ sendError (e .getClassName (), "Sorry, but there was an error handling that error!" );
65
+ } catch (Exception ex2 ) {
66
+ sendError ("[CLASSNAME IRRETRIEVABLE]" , "Sorry, but there was an error handling that error!" );
67
+ }
68
+ }
32
69
}
33
70
34
71
}
0 commit comments