/** * Recreate throwable from exception protoBuf which received from remote or local node. * if no match constructor found, the base Throwable (Exception or Error) is created as a substitution * * @param exceptionWrapper the exception protoBuf * @return Throwable deserialized from protoBuf */ public static Throwable getThrowable(UserBitShared.ExceptionWrapper exceptionWrapper) { if (exceptionWrapper == null) { return null; } String className = exceptionWrapper.getExceptionClass(); if (StringUtils.isBlank(className) || exceptionWrapper.getStackTraceCount() < 1) { return null; } Throwable inner = getThrowable(exceptionWrapper.getCause()); try { Throwable throwable = getInstance(className, exceptionWrapper.getMessage(), inner); int size = exceptionWrapper.getStackTraceCount(); StackTraceElement[] stackTrace = new StackTraceElement[size]; for (int i = 0; i < size; ++i) { UserBitShared.StackTraceElementWrapper w = exceptionWrapper.getStackTrace(i); stackTrace[i] = new StackTraceElement(w.getClassName(), w.getMethodName(), w.getFileName(), w.getLineNumber()); } throwable.setStackTrace(stackTrace); return throwable; } catch (Throwable t) { return null; } }
/** * Recreate throwable from exception protoBuf which received from remote or local node. * if no match constructor found, the base Throwable (Exception or Error) is created as a substitution * * @param exceptionWrapper the exception protoBuf * @return Throwable deserialized from protoBuf */ public static Throwable getThrowable(UserBitShared.ExceptionWrapper exceptionWrapper) { if (exceptionWrapper == null) { return null; } String className = exceptionWrapper.getExceptionClass(); if (StringUtils.isBlank(className) || exceptionWrapper.getStackTraceCount() < 1) { return null; } Throwable inner = getThrowable(exceptionWrapper.getCause()); try { Throwable throwable = getInstance(className, exceptionWrapper.getMessage(), inner); int size = exceptionWrapper.getStackTraceCount(); StackTraceElement[] stackTrace = new StackTraceElement[size]; for (int i = 0; i < size; ++i) { UserBitShared.StackTraceElementWrapper w = exceptionWrapper.getStackTrace(i); stackTrace[i] = new StackTraceElement(w.getClassName(), w.getMethodName(), w.getFileName(), w.getLineNumber()); } throwable.setStackTrace(stackTrace); return throwable; } catch (Throwable t) { return null; } }