> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/decision/attempt.md).

# Attempt

Create an Attempt object with or without a given value so you can do fluent operations on the registered attempt value.

## Method Signature

```
Attempt(value=[any])
```

### Arguments

| Argument | Type  | Required | Description                                                                                                         | Default |
| -------- | ----- | -------- | ------------------------------------------------------------------------------------------------------------------- | ------- |
| `value`  | `any` | `false`  | The value to store as the attempt. This can be a value, or a closure/lambda that will be executed to get the value. |         |

## Examples

### Create an Attempt with a value

Wraps a value in an Attempt object for fluent error-safe operations.

```java
attempt = attempt( 42 );
writeOutput( attempt.get() );

```

Result: 42

### Create an Attempt with a closure

The closure is executed and its result (or exception) is captured.

```java
attempt = attempt( () => 10 / 2 );
writeOutput( attempt.get() );

```

Result: 5

### Attempt that catches an exception

When the closure throws, the Attempt captures the failure instead of crashing.

```java
attempt = attempt( () => 10 / 0 );
writeOutput( attempt.hasError() );

```

Result: true

### Fluent chaining with Attempt

```java
result = attempt( () => "hello".len() )
    .map( (x) => x * 2 )
    .getOrDefault( 0 );
writeOutput( result );

```

Result: 10

### Attempt with no value

Creates an empty Attempt object for later use.

```java
attempt = attempt();
writeOutput( attempt.isEmpty() );

```

Result: true

## Related

* [ArrayIsEmpty](/boxlang-language/reference/built-in-functions/decision/arrayisempty.md)
* [arrayIsEmpty](https://github.com/ortus-boxlang/boxlang-docs/tree/v1.x/boxlang-language/reference/built-in-functions/decision/arrayIsEmpty.md)
* [IsArray](/boxlang-language/reference/built-in-functions/decision/isarray.md)
* [IsBinary](/boxlang-language/reference/built-in-functions/decision/isbinary.md)
* [IsBoolean](/boxlang-language/reference/built-in-functions/decision/isboolean.md)
* [IsBoxSet](/boxlang-language/reference/built-in-functions/decision/isboxset.md)
* [IsClosure](/boxlang-language/reference/built-in-functions/decision/isclosure.md)
* [IsCustomFunction](/boxlang-language/reference/built-in-functions/decision/iscustomfunction.md)
* [IsDate](/boxlang-language/reference/built-in-functions/decision/isdate.md)
* [IsDateObject](/boxlang-language/reference/built-in-functions/decision/isdateobject.md)
* [IsDebugMode](/boxlang-language/reference/built-in-functions/decision/isdebugmode.md)
* [IsDefined](/boxlang-language/reference/built-in-functions/decision/isdefined.md)
* [IsEmpty](/boxlang-language/reference/built-in-functions/decision/isempty.md)
* [IsFileObject](/boxlang-language/reference/built-in-functions/decision/isfileobject.md)
* [IsIPv6](/boxlang-language/reference/built-in-functions/decision/isipv6.md)
* [IsJSON](/boxlang-language/reference/built-in-functions/decision/isjson.md)
* [IsLeapYear](/boxlang-language/reference/built-in-functions/decision/isleapyear.md)
* [IsLocalHost](/boxlang-language/reference/built-in-functions/decision/islocalhost.md)
* [IsNull](/boxlang-language/reference/built-in-functions/decision/isnull.md)
* [IsNumeric](/boxlang-language/reference/built-in-functions/decision/isnumeric.md)
* [IsNumericDate](/boxlang-language/reference/built-in-functions/decision/isnumericdate.md)
* [IsObject](/boxlang-language/reference/built-in-functions/decision/isobject.md)
* [IsQuery](/boxlang-language/reference/built-in-functions/decision/isquery.md)
* [IsRange](/boxlang-language/reference/built-in-functions/decision/isrange.md)
* [IsSimpleValue](/boxlang-language/reference/built-in-functions/decision/issimplevalue.md)
* [IsStringBuilder](/boxlang-language/reference/built-in-functions/decision/isstringbuilder.md)
* [IsStruct](/boxlang-language/reference/built-in-functions/decision/isstruct.md)
* [IsValid](/boxlang-language/reference/built-in-functions/decision/isvalid.md)
* [IsXML](/boxlang-language/reference/built-in-functions/decision/isxml.md)
* [IsXmlAttribute](/boxlang-language/reference/built-in-functions/decision/isxmlattribute.md)
* [IsXMLDoc](/boxlang-language/reference/built-in-functions/decision/isxmldoc.md)
* [IsXMLElem](/boxlang-language/reference/built-in-functions/decision/isxmlelem.md)
* [IsXMLNode](/boxlang-language/reference/built-in-functions/decision/isxmlnode.md)
* [IsXMLRoot](/boxlang-language/reference/built-in-functions/decision/isxmlroot.md)
* [LSIsNumeric](/boxlang-language/reference/built-in-functions/decision/lsisnumeric.md)
* [structIsEmpty](/boxlang-language/reference/built-in-functions/decision/structisempty.md)


---

# 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://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/decision/attempt.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.
