Repository: microsoft/terminal
File: src/cascadia/TerminalApp/Pane.cpp (C++)

Code before:
    // fired after this handler returns, and will properly cleanup state.
    if (!_IsLeaf())
    {
        return;
    }

    const auto newConnectionState = _control.ConnectionState();
    const auto previousConnectionState = std::exchange(_connectionState, newConnectionState);

    if (newConnectionState < ConnectionState::Closed)
    {
        // Pane doesn't care if the connection isn't entering a terminal state.
        return;
    }

    if (previousConnectionState < ConnectionState::Connected && newConnectionState >= ConnectionState::Failed)
    {
        // A failure to complete the connection (before it has _connected_) is not covered by "closeOnExit".
        // This is to prevent a misconfiguration (closeOnExit: always, startingDirectory: garbage) resulting
        // in Terminal flashing open and immediately closed.
        return;
    }

    if (_profile)
    {
        auto mode = _profile.CloseOnExit();
        if ((mode == CloseOnExitMode::Always) ||
            (mode == CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed))
        {
            Close();
        }
    }
}

// Method Description:
// - Plays a warning note when triggered by the BEL control character,
//   using the sound configured for the "Critical Stop" system event.`
//   This matches the behavior of the Windows Console host.
// - Will also flash the taskbar if the bellStyle setting for this profile
//   has the 'visual' flag set
// Arguments:
// - <unused>
void Pane::_ControlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                      const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
{
    if (!_IsLeaf())
    {
        return;
    }
    if (_profile)
    {

Review comment (suggestion):
```suggestion
        const auto mode = _profile.CloseOnExit();
```

Code after:
    // fired after this handler returns, and will properly cleanup state.
    if (!_IsLeaf())
    {
        return;
    }

    const auto newConnectionState = _control.ConnectionState();
    const auto previousConnectionState = std::exchange(_connectionState, newConnectionState);

    if (newConnectionState < ConnectionState::Closed)
    {
        // Pane doesn't care if the connection isn't entering a terminal state.
        return;
    }

    if (previousConnectionState < ConnectionState::Connected && newConnectionState >= ConnectionState::Failed)
    {
        // A failure to complete the connection (before it has _connected_) is not covered by "closeOnExit".
        // This is to prevent a misconfiguration (closeOnExit: always, startingDirectory: garbage) resulting
        // in Terminal flashing open and immediately closed.
        return;
    }

    if (_profile)
    {
        const auto mode = _profile.CloseOnExit();
        if ((mode == CloseOnExitMode::Always) ||
            (mode == CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed))
        {
            Close();
        }
    }
}

// Method Description:
// - Plays a warning note when triggered by the BEL control character,
//   using the sound configured for the "Critical Stop" system event.`
//   This matches the behavior of the Windows Console host.
// - Will also flash the taskbar if the bellStyle setting for this profile
//   has the 'visual' flag set
// Arguments:
// - <unused>
void Pane::_ControlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                      const winrt::Windows::Foundation::IInspectable& /*eventArgs*/)
{
    if (!_IsLeaf())
    {
        return;
    }
    if (_profile)
    {