JsonProjectException#

Thrown by new JsonProject(optionsJson) when the options JSON can't be decoded or holds an invalid value. The constructor is the only JsonProject member that throws for bad input: the operations return an error envelope instead. JsonProjectException is unchecked and extends RuntimeException, not PlenException, so catch (PlenException e) doesn't catch it.

Declaration#

package org.dhtmlx.plen;

public final class JsonProjectException extends RuntimeException {
  public JsonProjectException(PlenException error)

  public String getErrorJson()
  public PlenException getError()
}

Constructors#

JsonProjectException#

public JsonProjectException(PlenException error)

Wraps an engine error. The message is the error envelope built by Wire.errorText(error), and error becomes the cause.

Name Type Description
error PlenException The error to wrap.

Methods#

getErrorJson#

public String getErrorJson()

Returns the error envelope as JSON text, the same shape the JsonProject operations return on failure:

{"error":{"code":null,"kind":"validation","message":"unknown validation","path":null},"ok":false}

kind is parse for malformed JSON or a value of the wrong JSON type, and validation for a value that decoded but isn't accepted, such as an unknown validation mode. getMessage() returns the same text.

getError#

public PlenException getError()

Returns the wrapped error, also available as getCause(). For options JSON it's an InputException; read its kind and path for typed handling.

Thrown by#

Call When
new JsonProject(String optionsJson) The options JSON is malformed, is null as a JSON document (the text "null"), or holds an invalid ProjectOptions value.

A Java null passed as optionsJson throws NullPointerException, not JsonProjectException. Wire.newProject decodes the same options and throws the unwrapped InputException.

Example#

import org.dhtmlx.plen.*;

public class JsonOptionsErrorExample {
  public static void main(String[] args) throws Exception {
    try {
      new JsonProject("{\"validation\":\"loose\"}");
    } catch (JsonProjectException e) {
      // send the envelope to the client as is
      System.out.println(e.getErrorJson());

      if (e.getError() instanceof InputException input) {
        System.out.println(input.kind + ": " + input.getMessage());
      }
    }
  }
}

Output:

{"error":{"code":null,"kind":"validation","message":"unknown validation","path":null},"ok":false}
VALIDATION: unknown validation