public static void createExceptionBreakPoint(VirtualMachine vm) { EventRequestManager erm = vm.eventRequestManager(); List<ReferenceType> referenceTypes = vm.classesByName("java.lang.Throwable"); for (ReferenceType refType : referenceTypes){ ExceptionRequest exceptionRequest = erm.createExceptionRequest(refType, true, true); exceptionRequest.setEnabled(true); } }
private void trapExceptions() { ReferenceType referenceType = vm.classesByName("java.lang.Throwable").get(0); vm.eventRequestManager().createExceptionRequest(referenceType, true, true).enable(); }
@Override public void setExceptionBreakpoints(boolean notifyCaught, boolean notifyUncaught) { EventRequestManager manager = vm.eventRequestManager(); ArrayList<ExceptionRequest> legacy = new ArrayList<>(manager.exceptionRequests()); manager.deleteEventRequests(legacy); // When no exception breakpoints are requested, no need to create an empty exception request. if (notifyCaught || notifyUncaught) { // from: https://www.javatips.net/api/REPLmode-master/src/jm/mode/replmode/REPLRunner.java // Calling this seems to set something internally to make the // Eclipse JDI wake up. Without it, an ObjectCollectedException // is thrown on request.enable(). No idea why this works, // but at least exception handling has returned. (Suspect that it may // block until all or at least some threads are available, meaning // that the app has launched and we have legit objects to talk to). vm.allThreads(); // The bug may not have been noticed because the test suite waits for // a thread to be available, and queries it by calling allThreads(). // See org.eclipse.debug.jdi.tests.AbstractJDITest for the example. // get only the uncaught exceptions ExceptionRequest request = manager.createExceptionRequest(null, notifyCaught, notifyUncaught); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); request.enable(); } }
ExceptionRequest req = erm.createExceptionRequest( list.get( 0 ), bp.isCaughtException(), bp.isUncaughtException() ); req.setEnabled( bp.isActive() && (bp.isActiveWhenMuted() || !_bpm.isMuted()) );