Snippets/Error Handling/try.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</Title>
                <Description>error handler with catch clause</Description>
                <Shortcut>try</Shortcut>
                <Keywords>scriptblock</Keywords>
                <Author>ISESteroids</Author>
                <DifficultyLevel>4</DifficultyLevel>
                <Example>False</Example>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                    <SnippetType>SurroundsWith</SnippetType>
                    <SnippetType>Refactor</SnippetType>
                </SnippetTypes>
                <Requirements>
                    <MinimumPowerShellVersion>1</MinimumPowerShellVersion>
                    <RequiredModules></RequiredModules>
                    <AdminPrivileges>False</AdminPrivileges>
                    <ProcessorArchitecture>x86,x64</ProcessorArchitecture>
                </Requirements>
            </Header>
            <Declarations>
                <Literal>
                   <ID><![CDATA[10;9;0]]></ID>
                   <Default></Default>
                   <ToolTip><![CDATA[]]></ToolTip>
                   <ToolTipStatusbar><![CDATA[code to monitor for errors]]></ToolTipStatusbar>
                   <EncloseSelection>true</EncloseSelection>
                   <SupportsSurroundsWith>true</SupportsSurroundsWith>
                </Literal>
                <Literal>
                   <ID><![CDATA[38;89;0]]></ID>
                   <Default></Default>
                   <ToolTip><![CDATA[]]></ToolTip>
                   <ToolTipStatusbar><![CDATA[Error Handler]]></ToolTipStatusbar>
                </Literal>
            </Declarations>
 
 
            <Code>
                <Script Language='PowerShell' CaretOffset='134'>
                    <![CDATA[try
{
  # Content
 
}
catch
{
  "Error was $_"
  $line = $_.InvocationInfo.ScriptLineNumber
  "Error was in Line $line"
}
 
]]>
                </Script>
            </Code>
 
    </Snippet>
</Snippets>