浅谈Try catch finally 与using
2010-01-17 22:23
399 查看
对于Try catch finally,大家应该都不陌生,您接触的写法可能会是下面的记几种类型:
Try catch (您可以匹配多个catch)
try
{
}
catch (Exception)
{
throw;
}
Try finally
try
{
}
finally
{
}
Try catch finally (同样,你一样可以匹配多个catch)
usingTry<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>usingTry</Title>
<Shortcut>usingTry</Shortcut>
<Description>Code snippet for using statement add Try</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>resource</ID>
<ToolTip>Resource to use</ToolTip>
<Default>resource</Default>
</Literal>
<Literal>
<ID>expression</ID>
<ToolTip>Exception type</ToolTip>
<Function>SimpleTypeName(global::System.Exception)</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
using($resource$)
{
try
{
$selected$
}
catch ($expression$)
{
$end$
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
至此,完成了一个加强版的using,和使用普通的using是一样的。
Try catch (您可以匹配多个catch)
try
{
}
catch (Exception)
{
throw;
}
Try finally
try
{
}
finally
{
}
Try catch finally (同样,你一样可以匹配多个catch)
usingTry<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>usingTry</Title>
<Shortcut>usingTry</Shortcut>
<Description>Code snippet for using statement add Try</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>resource</ID>
<ToolTip>Resource to use</ToolTip>
<Default>resource</Default>
</Literal>
<Literal>
<ID>expression</ID>
<ToolTip>Exception type</ToolTip>
<Function>SimpleTypeName(global::System.Exception)</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
using($resource$)
{
try
{
$selected$
}
catch ($expression$)
{
$end$
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
至此,完成了一个加强版的using,和使用普通的using是一样的。
相关文章推荐
- C# using 与Try-catch-finally的区别和用法
- using 和 try catch finally 的用法
- using try catch finally in SQL
- 浅谈try catch finally
- try、catch、finally 执行顺序 及 return 关系浅谈一
- 可以使用 using 或者 try-catch-finally 调用 Dispose() 来释放非托管资源
- C# using 与Try-catch-finally的区别和用法
- 浅谈如何用try、catch、finally捕获异常
- 浅谈try catch finally
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- 有return的情况下try catch finally的执行顺序
- 【知识积累】try-catch-finally+return总结
- C#中的异常捕获机制(try catch finally)
- try-catch-finally的执行顺序
- 如何缩减Try{}Catch{}Finally{}代码----定义一个公用的Try{}Catch{}Finally{}
- return 于try{}catch(Exception e){}finally{}语句结合使用的一点注意事项
- C# try, catch ,finally
- java中的异常处理 try-catch 以及try-catch-finally
- 有return的情况下try catch finally的执行顺序
- Java中try-catch-finally语句块的应用