Azure / Azure/azure-powershell

Exception thrown by Get-AzServiceBusNamespace is not being catch in catch block

Open
#23,958 2 comments 0 reactions 0 assignees View on GitHub
act-observability-squad bug customer-reported Service Attention Service Bus
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

`
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3
try
{
Get-AzServiceBusNamespace -ResourceGroupName invalidResourceGroup -Name invalidNsName
Write-Output "Exception not thrown!"
} catch {
Write-Output "Exception thrown!"
}`

I would expect to print 'Exception thrown!' for invalid resource group but its printing "Exception not thrown!", Even though I can see exception on the console Resource group invalidResourceGroup could not be found.

### Issue script & Debug output

```PowerShell
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.2.13
PSEdition Core
GitCommitId 7.2.13
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 6.5.1 Az.Resources {Export-AzResourceGroup, Export-
AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeploymen…
```

### Error output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.