Skip to content

Conversation

testforstephen
Copy link
Contributor

@testforstephen testforstephen commented Apr 23, 2023

this requires microsoft/java-debug#481

Fixes #1175
Fixes #295

Here is how to enable exception breakpoint on the specified exception type:

  1. Configure the exception types in the setting java.debug.settings.exceptionBreakpoint.exceptionTypes.
    "java.debug.settings.exceptionBreakpoint.exceptionTypes": [
       "java.lang.NullPointerException" // fully qualified class name
    ]
  1. Go to Breakpoint view, toggle the CaughtException or UncaughtException.
    image

@testforstephen
Copy link
Contributor Author

With the sample code below, I want to break on the exception MyCustomException only.

package org.springframework.samples.petclinic;

public class ExceptionTest {
    public static void main(String[] args) {
        try {
            throw new NullPointerException("NPE");
        } catch (NullPointerException e) {
            System.out.println("Catch NPE.");
        }

        try {
            System.out.println("try");
            throw new MyCustomException("custom");
        } catch (Exception e) {
            System.out.println("catch");
        } finally {
            System.out.println("finally");
        }
    }

    static class MyCustomException extends Exception {
        public MyCustomException(String message) {
            super(message);
        }
    }
}

Firstly you need to toggle caught/uncaught Exception in Breakpoint view.
image

Then go to settings.json, customize the breakpoint filters. Two kinds of filters both work for the purpose above:

  1. Specify the target exception type directly:
    "java.debug.settings.exceptionBreakpoint.exceptionTypes": [
        "org.springframework.samples.petclinic.ExceptionTest$MyCustomException",
    ],
    "java.debug.settings.exceptionBreakpoint.allowClasses": [
    ],
    "java.debug.settings.exceptionBreakpoint.skipClasses": [
   ]
  1. Specify the locations where the exception breakpoint can break on:
    "java.debug.settings.exceptionBreakpoint.exceptionTypes": [
    ],
    "java.debug.settings.exceptionBreakpoint.allowClasses": [
        "*.ExceptionTest"
    ],
    "java.debug.settings.exceptionBreakpoint.skipClasses": [
    ]

@testforstephen testforstephen merged commit 9f87152 into microsoft:main Apr 23, 2023
@testforstephen testforstephen deleted the jinbo_exception branch April 23, 2023 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to break on caught/uncaught exceptions by name or package namespace [Feature] Exception filter for handled/unhandled exception
2 participants