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


# ProjectException

Thrown when a call doesn't fit the current state of a [`Project`](<https://docs.dhtmlx.com/planning-engine/java/api/project/project.md>): the project has no solved baseline, a baseline token is out of date, or an earlier [`apply`](<https://docs.dhtmlx.com/planning-engine/java/api/project-apply.md>) rejected operations. The [`code`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/project-exception.md#code>) field says which.

## Declaration

```java
package org.dhtmlx.plen;

public class ProjectException extends PlenException
```

Unchecked: it extends [`PlenException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/plen-exception.md>), a `RuntimeException`, and no method declares it in `throws`. `catch (PlenException e)` also catches it.

## Constructors

### ProjectException(ProjectError)

```java
public ProjectException(ProjectError code)
```

Creates the exception with the given code. The message is the code's kebab-case spelling.

**Parameters**

| Name | Type | Description |
|---|---|---|
| `code` | [`ProjectError`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/project-exception.md#projecterror>) | The error code |

## Fields

### code

```java
public ProjectError code
```

The error code. Branch on it to pick the recovery.

## Methods

### withCode

```java
public ProjectException withCode(ProjectError value)
```

Sets `code` and returns this exception. The message keeps the spelling of the code passed to the constructor.

### getMessage

```java
public String getMessage()
```

Inherited from `Throwable`. Returns the kebab-case code: `"no-baseline"`, `"stale-baseline"` or `"needs-resync"`.

## ProjectError

The code of a `ProjectException`.

```java
package org.dhtmlx.plen;

public enum ProjectError {
    NO_BASELINE,
    STALE_BASELINE,
    NEEDS_RESYNC
}
```

| Value | Message | When it occurs | Thrown by |
|---|---|---|---|
| `NO_BASELINE` | `no-baseline` | The project has no solved baseline: it was never solved, or it has unsolved edits after `apply` | [`preview`](<https://docs.dhtmlx.com/planning-engine/java/api/project-preview.md>), [`loadProfile`](<https://docs.dhtmlx.com/planning-engine/java/api/project-load-profile.md>), [`evaluate`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md>), [`suggestAssignments`](<https://docs.dhtmlx.com/planning-engine/java/api/project-suggest-assignments.md>), [`roster`](<https://docs.dhtmlx.com/planning-engine/java/api/project-roster.md>) |
| `STALE_BASELINE` | `stale-baseline` | A `baselineId` in the options or in [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/scheduling-changes.md>) doesn't name the current baseline. A `null` `baselineId` is never checked | [`preview`](<https://docs.dhtmlx.com/planning-engine/java/api/project-preview.md>), [`apply`](<https://docs.dhtmlx.com/planning-engine/java/api/project-apply.md>), [`loadProfile`](<https://docs.dhtmlx.com/planning-engine/java/api/project-load-profile.md>), [`evaluate`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md>), [`suggestAssignments`](<https://docs.dhtmlx.com/planning-engine/java/api/project-suggest-assignments.md>) |
| `NEEDS_RESYNC` | `needs-resync` | An earlier `apply` rejected an operation, and no full `solve(data, …)` has followed. Only a `solve` with non-null data clears it | [`solve`](<https://docs.dhtmlx.com/planning-engine/java/api/project-solve.md>) with `null` data, [`apply`](<https://docs.dhtmlx.com/planning-engine/java/api/project-apply.md>), [`level`](<https://docs.dhtmlx.com/planning-engine/java/api/project-level.md>) |

[`SkillLayer.slots`](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md>) reports `NO_BASELINE` as a [`MatchException.Project`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/match-exception.md>) that wraps a `ProjectException`.

For how to recover from each code, see [Error handling](<https://docs.dhtmlx.com/planning-engine/java/error-handling.md#project-errors>).

## Example

```java
import org.dhtmlx.plen.*;

public class NoBaseline {
    public static void main(String[] args) throws Exception {
        var project = new Project();
        try {
            project.preview(new SchedulingChanges(), new PreviewOptions());
        } catch (ProjectException e) {
            if (e.code == ProjectError.NO_BASELINE) {
                System.out.println(e.getMessage()); // no-baseline
            }
        }
    }
}
```

## Related

- [`PlenException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/plen-exception.md>) - the base class
- [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>) - the error for invalid input
- [`Project`](<https://docs.dhtmlx.com/planning-engine/java/api/project/project.md>) - the stateful project whose state is checked
- [Error handling](<https://docs.dhtmlx.com/planning-engine/java/error-handling.md#project-errors>) - telling the codes apart and recovering
- [Recover from rejected changes](<https://docs.dhtmlx.com/planning-engine/java/how-to/recover-from-rejected-changes.md>) - clearing `NEEDS_RESYNC`
