Skip to content

Commit

Permalink
docs: Adding docs for default values on Exception fields. (#156)
Browse files Browse the repository at this point in the history
* docs: Adding docs for default values on Exception fields

* docs: Default values for Exceptions docs improvement
  • Loading branch information
klkucaj authored Aug 28, 2024
1 parent 5b6f17e commit e0d6e2c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/06-concepts/04-exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,25 @@ catch(e) {
print('Something else went wrong.');
}
```

### Default Values in Exceptions

Serverpod allows you to specify default values for fields in exceptions, similar to how it's done in models using the `default` and `defaultModel` keywords. If you're unfamiliar with how these keywords work, you can refer to the [Default Values](models#default-values) section in the [Working with Models](models) documentation.

:::info
Since exceptions are not persisted in the database, the `defaultPersist` keyword is not supported. If both `default` and `defaultModel` are specified, `defaultModel` will always take precedence, making it unnecessary to use both.
:::

**Example:**

```yaml
exception: MyException
fields:
message: String, default="An error occurred"
errorCode: int, default=1001
```

In this example:

- The `message` field will default to `"An error occurred"` if not provided.
- The `errorCode` field will default to `1001`.

0 comments on commit e0d6e2c

Please sign in to comment.