Skip to content

missing closing brace. #50066

@vivekuno

Description

@vivekuno

Type of issue

Typo

Description

Hi,
The function ToastBreadAsync is missing closing brace "}" marking the end of the block.
// Non-async, task-returning method.
// Within this method (but outside of the local function),
// any thrown exceptions emerge synchronously.
public static Task ToastBreadAsync(int slices, int toastTime)
{
if (slices is < 1 or > 4)
{
throw new ArgumentException(
"You must specify between 1 and 4 slices of bread.",
nameof(slices));
}

if (toastTime < 1)
{
    throw new ArgumentException(
        "Toast time is too short.", nameof(toastTime));
}

return ToastBreadAsyncCore(slices, toastTime);

} <<<<<<<< Here

// Local async function.
// Within this function, any thrown exceptions are stored in the task.
static async Task<Toast> ToastBreadAsyncCore(int slices, int time)
{
    for (int slice = 0; slice < slices; slice++)
    {
        Console.WriteLine("Putting a slice of bread in the toaster");
    }
    // Start toasting.
    await Task.Delay(time);

    if (time > 2_000)
    {
        throw new InvalidOperationException("The toaster is on fire!");
    }

    Console.WriteLine("Toast is ready!");

    return new Toast();
}

} <<< Incorrect.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/exceptions/creating-and-throwing-exceptions

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/fundamentals/exceptions/creating-and-throwing-exceptions.md

Document Version Independent Id

4d98bec1-a03a-4a9c-4108-cb847f9c18bd

Platform Id

4476e67a-3bdf-33df-dc3a-38e385729bc9

Article author

@BillWagner

Metadata

  • ID: cfeeac2f-fbeb-b4b5-ff02-fd48a28a2768
  • PlatformId: 4476e67a-3bdf-33df-dc3a-38e385729bc9
  • Service: dotnet-csharp
  • Sub-service: fundamentals

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions