[Canonical page](<https://docs.dhtmlx.com/planning-engine/net/api/core/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/net/api/core/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/net/api/project-apply.md>) rejected operations. [`Code`](<https://docs.dhtmlx.com/planning-engine/net/api/core/errors/project-exception.md#code>) says which.

## Declaration

```csharp
namespace Plen;

public sealed class ProjectException : PlenException
```

Derives from [`PlenException`](<https://docs.dhtmlx.com/planning-engine/net/api/core/errors/plen-exception.md>), so `catch (PlenException)` also catches it.

## Constructors

### ProjectException(ProjectError)

```csharp
public ProjectException(ProjectError code)
```

Creates the exception with the given code. `Message` is set to the code's kebab-case spelling.

**Parameters**

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

## Properties

### Code

```csharp
public ProjectError Code { get; }
```

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

### Message

```csharp
public virtual string Message { get; }
```

Inherited from `Exception`. The kebab-case code: `"no-baseline"`, `"stale-baseline"` or `"needs-resync"`.

## ProjectError

The code of a `ProjectException`.

```csharp
namespace Plen;

public enum ProjectError
{
    NoBaseline,
    StaleBaseline,
    NeedsResync,
}
```

| Variant | `Message` | When it occurs | Thrown by |
|---|---|---|---|
| `NoBaseline` | `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/net/api/project-preview.md>), [`LoadProfile`](<https://docs.dhtmlx.com/planning-engine/net/api/project-load-profile.md>), [`Evaluate`](<https://docs.dhtmlx.com/planning-engine/net/api/project-evaluate.md>), [`SuggestAssignments`](<https://docs.dhtmlx.com/planning-engine/net/api/project-suggest-assignments.md>), [`Roster`](<https://docs.dhtmlx.com/planning-engine/net/api/project-roster.md>), [`SkillLayer.Slots`](<https://docs.dhtmlx.com/planning-engine/net/api/skill-layer-slots.md>) |
| `StaleBaseline` | `stale-baseline` | A `BaselineId` in the options or in [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/net/api/core/changes/scheduling-changes.md>) doesn't name the current baseline. A `null` `BaselineId` is never checked | [`Preview`](<https://docs.dhtmlx.com/planning-engine/net/api/project-preview.md>), [`Apply`](<https://docs.dhtmlx.com/planning-engine/net/api/project-apply.md>), [`LoadProfile`](<https://docs.dhtmlx.com/planning-engine/net/api/project-load-profile.md>), [`Evaluate`](<https://docs.dhtmlx.com/planning-engine/net/api/project-evaluate.md>), [`SuggestAssignments`](<https://docs.dhtmlx.com/planning-engine/net/api/project-suggest-assignments.md>) |
| `NeedsResync` | `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/net/api/project-solve.md>) with `null` data, [`Apply`](<https://docs.dhtmlx.com/planning-engine/net/api/project-apply.md>), [`Level`](<https://docs.dhtmlx.com/planning-engine/net/api/project-level.md>) |

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

## Example

```csharp
using Plen;

var project = new Project();
var changes = new SchedulingChanges();

try
{
    project.Preview(changes, new PreviewOptions());
}
catch (ProjectException e) when (e.Code == ProjectError.NoBaseline)
{
    Console.WriteLine(e.Message); // no-baseline
}
```

## Related

- [`PlenException`](<https://docs.dhtmlx.com/planning-engine/net/api/core/errors/plen-exception.md>) - the base class to catch every engine failure
- [`InputException`](<https://docs.dhtmlx.com/planning-engine/net/api/core/errors/input-exception.md>) - the other engine exception, for invalid input
- [`Project`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/project.md>) - the stateful project whose calls throw it
- [Error handling](<https://docs.dhtmlx.com/planning-engine/net/error-handling.md>) - recovering from each code
- [Recover from rejected changes](<https://docs.dhtmlx.com/planning-engine/net/how-to/recover-from-rejected-changes.md>) - clearing `NeedsResync` after a rejected `Apply`
