/** * Outputs an exception with its StackTrace on a JSon stream. * * @param generator JSonGenerator. * @param sentryException Sentry exception with its associated {@link StackTraceInterface}. * @throws IOException */ private void writeException(JsonGenerator generator, SentryException sentryException) throws IOException { generator.writeStartObject(); generator.writeStringField(TYPE_PARAMETER, sentryException.getExceptionClassName()); generator.writeStringField(VALUE_PARAMETER, sentryException.getExceptionMessage()); generator.writeStringField(MODULE_PARAMETER, sentryException.getExceptionPackageName()); generator.writeFieldName(STACKTRACE_PARAMETER); stackTraceInterfaceBinding.writeInterface(generator, sentryException.getStackTraceInterface()); generator.writeEndObject(); }
/** * Creates a new instance from the given {@code throwable}. * * @param throwable the {@link Throwable} to build this instance from */ public ExceptionInterface(final Throwable throwable) { this(SentryException.extractExceptionQueue(throwable)); }
Deque<SentryException> throwables = ((ExceptionInterface) sentryInterface).getExceptions(); for (SentryException throwable : throwables) { for (SentryStackTraceElement traceElement : throwable.getStackTraceInterface().getStackTrace()) { String plugin = PluginClassloader.getPluginWhichLoaded(traceElement.getModule()); if (plugin != null) {
/** * Transforms a {@link Throwable} into a Queue of {@link SentryException}. * <p> * Exceptions are stored in the queue from the most recent one to the oldest one. * * @param throwable throwable to transform in a queue of exceptions. * @return a queue of exception with StackTrace. */ public static Deque<SentryException> extractExceptionQueue(Throwable throwable) { Deque<SentryException> exceptions = new ArrayDeque<>(); Set<Throwable> circularityDetector = new HashSet<>(); StackTraceElement[] childExceptionStackTrace = new StackTraceElement[0]; //Stack the exceptions to send them in the reverse order while (throwable != null && circularityDetector.add(throwable)) { exceptions.add(new SentryException(throwable, childExceptionStackTrace)); childExceptionStackTrace = throwable.getStackTrace(); throwable = throwable.getCause(); } return exceptions; }