Snippets/Error Handling/try-catch-finally.snippets.ps1xml
<?xml version='1.0' encoding='utf-8' ?>
<Snippets xmlns='http://schemas.microsoft.com/PowerShell/Snippets'> <Snippet Version='1.0.0'> <Header> <Title>try-catch-finally</Title> <Description></Description> <Shortcut></Shortcut> <Keywords>ScriptBlock</Keywords> <Author>Tobias</Author> <DifficultyLevel>1</DifficultyLevel> <Example>False</Example> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> <Requirements> <MinimumPowerShellVersion>1</MinimumPowerShellVersion> <RequiredModules></RequiredModules> <AdminPrivileges>False</AdminPrivileges> <ProcessorArchitecture>x86,x64</ProcessorArchitecture> </Requirements> </Header> <Code> <Script Language='PowerShell' CaretOffset='241'> <![CDATA[try { 1/0 } catch [DivideByZeroException] { Write-Host 'Divide by zero exception' } catch [System.Net.WebException],[System.Exception] { Write-Host 'Other exception' } finally { Write-Host 'cleaning up ...' } ]]> </Script> </Code> </Snippet> </Snippets> |