[Canonical page](<https://docs.dhtmlx.com/planning-engine/java/api/json/json-project-exception/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# JsonProjectException

Thrown by [`new JsonProject(optionsJson)`](<https://docs.dhtmlx.com/planning-engine/java/api/json/json-project.md>) 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`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/plen-exception.md>), so `catch (PlenException e)` doesn't catch it.

## Declaration

```java
package org.dhtmlx.plen;

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

  public String getErrorJson()
  public PlenException getError()
}
```

## Constructors

### JsonProjectException

```java
public JsonProjectException(PlenException error)
```

Wraps an engine error. The message is the error envelope built by [`Wire.errorText(error)`](<https://docs.dhtmlx.com/planning-engine/java/api/json/wire.md#errortext>), and `error` becomes the cause.

| Name | Type | Description |
|---|---|---|
| `error` | [`PlenException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/plen-exception.md>) | The error to wrap. |

## Methods

### getErrorJson

```java
public String getErrorJson()
```

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

```json
{"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

```java
public PlenException getError()
```

Returns the wrapped error, also available as `getCause()`. For options JSON it's an [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>); read its `kind` and `path` for typed handling.

## Thrown by

| Call | When |
|---|---|
| [`new JsonProject(String optionsJson)`](<https://docs.dhtmlx.com/planning-engine/java/api/json/json-project.md>) | The options JSON is malformed, is `null` as a JSON document (the text `"null"`), or holds an invalid [`ProjectOptions`](<https://docs.dhtmlx.com/planning-engine/java/api/project/project-options.md>) value. |

A Java `null` passed as `optionsJson` throws `NullPointerException`, not `JsonProjectException`. [`Wire.newProject`](<https://docs.dhtmlx.com/planning-engine/java/api/json/wire.md#newproject>) decodes the same options and throws the unwrapped `InputException`.

## Example

```java
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
```

## Related

- [`JsonProject`](<https://docs.dhtmlx.com/planning-engine/java/api/json/json-project.md>) - the constructor that throws it
- [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>) - the wrapped error
- [`Wire`](<https://docs.dhtmlx.com/planning-engine/java/api/json/wire.md#errortext>) - builds the error envelope it carries
- [Error handling](<https://docs.dhtmlx.com/planning-engine/java/error-handling.md#errors-in-the-json-api>) - errors in the JSON API
