Skip to content

io microsphere util StackTraceUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

StackTraceUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/StackTraceUtils.java

Overview

The utility class for Stack Trace

Declaration

public abstract class StackTraceUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getStackTrace

StackTraceElement[] stackTrace = StackTraceUtils.getStackTrace();
for (StackTraceElement element : stackTrace) {
    System.out.println(element);
}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.util.StackTraceUtils;

API Reference

Public Methods

Method Description
getCallerClassInStatckTrace StackTraceElement invocation frame offset
getCallerClassNameInStackTrace General implementation, get the calling class name
getCallerClassInStatckTrace Get caller class in General JVM
getCallerClassNameInStackTrace General implementation, get the calling class name by specifying the calling level value
getStackTrace Get the StackTraceElement array on the current thread

Method Details

getCallerClassInStatckTrace

public static Class<?> getCallerClassInStatckTrace()

StackTraceElement invocation frame offset / private static final int invocationFrameOffset;

// Initialize java.lang.StackTraceElement static { int offset = 0; // Use java.lang.StackTraceElement to calculate frame StackTraceElement[] stackTraceElements = getStackTrace(); for (; ; offset++) { StackTraceElement stackTraceElement = stackTraceElements[offset]; String className = stackTraceElement.getClassName(); if (TYPE.getName().equals(className)) { break; } } invocationFrameOffset = offset; }

/** Get caller class from Thread#getStackTrace() stack traces

getCallerClassNameInStackTrace

public static String getCallerClassNameInStackTrace(int invocationFrame)

General implementation, get the calling class name by specifying the calling level value

getStackTrace

public static StackTraceElement[] getStackTrace()

Get the StackTraceElement array on the current thread

See Also

  • StackTraceElement

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally