> For the complete documentation index, see [llms.txt](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/tryparse.md).

# tryParse

Namespace: `FsToolkit.ErrorHandling`

`tryParse` tries to parse a string value into a specified type using the type's `TryParse` method. Returns `Some value` if parsing succeeds, or `None` if it fails.

> **Note:** This function is not available when using Fable (JavaScript/Python compilation).

## Function Signature

```fsharp
string -> ^value option
```

where `^value` has a static member `TryParse: string * byref<^value> -> bool`.

## Examples

### Example 1 — Parsing an integer

```fsharp
let result : int option =
    Option.tryParse "42"

// Some 42
```

### Example 2 — Parsing failure

```fsharp
let result : int option =
    Option.tryParse "not a number"

// None
```

### Example 3 — Parsing a boolean

```fsharp
let result : bool option =
    Option.tryParse "true"

// Some true
```

### Example 4 — Parsing a DateTime

```fsharp
let result : System.DateTime option =
    Option.tryParse "2024-01-15"

// Some 2024-01-15T00:00:00
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/tryparse.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
