@Override public JsonElement serialize(Throwable src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.add("class", new JsonPrimitive(src.getClass().getName())); if (src.getMessage() != null) { jsonObject.add("message", new JsonPrimitive(src.getMessage())); } return jsonObject; }
/** * Signal exceptional cancellation of this job. * * @param ex exception causing the termination of job. */ public void cancel(Throwable ex) { if (ex instanceof JobCancelledException || ex.getMessage() != null && ex.getMessage().contains("job was cancelled")) return; if (ex instanceof IllegalArgumentException || ex.getCause() instanceof IllegalArgumentException) { cancel("Illegal argument: " + ex.getMessage()); return; } StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); String stackTrace = sw.toString(); cancel( "Got exception '" + ex.getClass() + "', with msg '" + ex.getMessage() + "'\n" + stackTrace, JobState.FAILED); if (_fjtask != null && !_fjtask.isDone()) _fjtask.completeExceptionally(ex); }