File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
plugin/src/main/groovy/org/unify4j/common Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,27 @@ public static Throwable getDeepestException(Throwable e) {
29
29
}
30
30
return e ;
31
31
}
32
+
33
+ /**
34
+ * Retrieves the class name and line number from the stack trace of the provided
35
+ * exception. This method is used to extract and return a string representation of
36
+ * where the exception occurred, specifically the class and line number of the first
37
+ * element in the stack trace.
38
+ * <p>
39
+ * If the exception or its stack trace is null or empty, the method returns an empty
40
+ * string or "Unknown" as a fallback.
41
+ *
42
+ * @param e The {@link Exception} from which to extract the stack trace information.
43
+ * @return A {@link String} representing the class name and line number in the format
44
+ * "ClassName:LineNumber", or "Unknown" if the stack trace is not available.
45
+ */
46
+ public static String getClassLine (Exception e ) {
47
+ if (e == null ) {
48
+ return "" ;
49
+ }
50
+ StackTraceElement [] trace = e .getStackTrace ();
51
+ return (trace != null && trace .length > 0 )
52
+ ? trace [0 ].getClassName () + ":" + trace [0 ].getLineNumber ()
53
+ : "Unknown" ;
54
+ }
32
55
}
You can’t perform that action at this time.
0 commit comments