# NotThrow

## ShouldNotThrowAction

```cs
var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
Should.NotThrow(() =>
                {
                    var y = homer.Salary / denominator;
                });
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/ShouldNotThrowExamples.ShouldNotThrowAction.codeSample.approved.cs#L1-L6) | [anchor](#snippet-ShouldNotThrowExamples.ShouldNotThrowAction.codeSample.approved.cs)

**Exception**

```
`var y = homer.Salary / denominator;`
    should not throw but threw
System.DivideByZeroException
    with message
"Attempted to divide by zero."
```

## ShouldNotThrow Action Extension

```cs
var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
var action = () =>
                {
                    var y = homer.Salary / denominator;
                };
action.ShouldNotThrow();
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/ShouldNotThrowExamples.ShouldNotThrowActionExtension.codeSample.approved.cs#L1-L7) | [anchor](#snippet-ShouldNotThrowExamples.ShouldNotThrowActionExtension.codeSample.approved.cs)

**Exception**

```
`action()`
    should not throw but threw
System.DivideByZeroException
    with message
"Attempted to divide by zero."
```

## ShouldNotThrowFunc

```cs
string? name = null;
Should.NotThrow(() => new Person(name!));
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/ShouldNotThrowExamples.ShouldNotThrowFunc.codeSample.approved.cs#L1-L2) | [anchor](#snippet-ShouldNotThrowExamples.ShouldNotThrowFunc.codeSample.approved.cs)

**Exception**

```
`new Person(name!)`
    should not throw but threw
System.ArgumentNullException
    with message
"Value cannot be null. (Parameter 'name')"
```

## ShouldNotThrow Func Extension

```cs
string? name = null;
var func = () => new Person(name!);
func.ShouldNotThrow();
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/ShouldNotThrowExamples.ShouldNotThrowFuncExtension.codeSample.approved.cs#L1-L3) | [anchor](#snippet-ShouldNotThrowExamples.ShouldNotThrowFuncExtension.codeSample.approved.cs)

**Exception**

```
`func()`
    should not throw but threw
System.ArgumentNullException
    with message
"Value cannot be null. (Parameter 'name')"
```

## ShouldNotThrowFuncOfTask

```cs
var homer = new Person { Name = "Homer", Salary = 30000 };
var denominator = 0;
Should.NotThrow(() =>
                {
                    var task = Task.Factory.StartNew(
                        () =>
                        {
                            var y = homer.Salary / denominator;
                        });
                    return task;
                });
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/ShouldNotThrowExamples.ShouldNotThrowFuncOfTask.codeSample.approved.cs#L1-L11) | [anchor](#snippet-ShouldNotThrowExamples.ShouldNotThrowFuncOfTask.codeSample.approved.cs)

**Exception**

```
`var task = Task.Factory.StartNew( () => { var y = homer.Salary / denominator; }); return task;`
    should not throw but threw
System.DivideByZeroException
    with message
"Attempted to divide by zero."
```


---

# Agent Instructions: 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:

```
GET https://docs.shouldly.org/documentation/exceptions/notthrow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
