Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Exception profiling

Goals of exception profiling

YourKit Java Profiler records thrown exceptions and their stack traces. Use this data to find performance bottlenecks and unexpected error paths.

Creating exceptions is expensive

Throwing exceptions can be expensive, especially when it happens frequently. Creating a java.lang.Throwable object usually calls java.lang.Throwable.fillInStackTrace(). This operation is expensive because the JVM must walk the current call stack and record the stack trace.

Practical rule #1: Do not create an exception unless you are going to throw it. If you do not need a stack trace, use a stackless exception.

Throwing and catching exceptions is expensive

When an exception is thrown, the JVM must:

  1. Search the current method and its callers for a matching catch handler.
  2. Unwind the stack until it reaches that handler.
  3. Interrupt the normal control flow, which is harder for the processor and JIT compiler to optimize.

Practical rule #2: Use exceptions for rare error conditions, not for loops, parsing data that is expected to be invalid, or normal control flow. When an event is expected to occur frequently, prefer an explicit check, a special return value, or a dedicated result type such as java.util.Optional.

Controlling exception profiling

Profiler UI

When the profiler is connected to the profiled application, the toolbar contains the following exception profiling controls:

Toolbar Button Description
Start exception profiling button Stop exception profiling button Start/Stop exception profiling.
Clear exception profiling results button Clear exception profiling results.

When exception profiling is started, previous results are cleared automatically.

Agent startup options

Exception profiling is enabled by default, but this can be adjusted with the following agent startup options:

  • exceptions=on enables exception events in the JVM and immediately starts the exception profiling. This is the default mode.
  • exceptions=off enables exception events in the JVM but does not immediately start the exception profiling that can instead be started later in runtime.
  • exceptions=disable fully disables exception events in the JVM to totally eliminate corresponding overhead.

HTTP API

For users requiring remote control or automation within their profiling workflows, YourKit Java Profiler offers control over the exception profiling through HTTP API endpoints. The documentation outlines startExceptionProfiling, stopExceptionProfiling and resetExceptionProfiling methods available for this purpose.

Java API

The YourKit Java Profiler also provides a Java API for deep integration with Java applications. The com.yourkit.api.controller.v3.Controller includes methods for starting, stopping, and resetting the exception profiling, similar to the toolbar buttons.

Triggers

Profiler built-in triggers allow to start exception profiling, by timer, on entering particular method, or by other conditions.

Exceptions tab

Exception profiling results can be analyzed from different perspectives:

YourKit uses cookies and other technologies to improve your browsing experience on our website, to show you personalized content, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the YourKit privacy policy.