本文整理汇总了VB.NET中System.CodeDom.CodeCatchClause类的典型用法代码示例。如果您正苦于以下问题:VB.NET CodeCatchClause类的具体用法?VB.NET CodeCatchClause怎么用?VB.NET CodeCatchClause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CodeCatchClause类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: New
' Declares a type to contain a try...catch block.
Dim type1 As New CodeTypeDeclaration("TryCatchTest")
' Defines a method that throws an exception of type System.ApplicationException.
Dim method1 As New CodeMemberMethod()
method1.Name = "ThrowApplicationException"
method1.Statements.Add(New CodeThrowExceptionStatement( _
New CodeObjectCreateExpression("System.ApplicationException", New CodePrimitiveExpression("Test Application Exception"))))
type1.Members.Add(method1)
' Defines a constructor that calls the ThrowApplicationException method from a try block.
Dim constructor1 As New CodeConstructor()
constructor1.Attributes = MemberAttributes.Public
type1.Members.Add(constructor1)
' Defines a try statement that calls the ThrowApplicationException method.
Dim try1 As New CodeTryCatchFinallyStatement()
try1.TryStatements.Add(New CodeMethodInvokeExpression(New CodeThisReferenceExpression(), "ThrowApplicationException"))
constructor1.Statements.Add(try1)
' Defines a catch clause for exceptions of type ApplicationException.
Dim catch1 As New CodeCatchClause("ex", New CodeTypeReference("System.ApplicationException"))
catch1.Statements.Add(New CodeCommentStatement("Handle any System.ApplicationException here."))
try1.CatchClauses.Add(catch1)
' Defines a catch clause for any remaining unhandled exception types.
Dim catch2 As New CodeCatchClause("ex")
catch2.Statements.Add(New CodeCommentStatement("Handle any other exception type here."))
try1.CatchClauses.Add(catch2)
' Defines a finally block by adding to the FinallyStatements collection.
try1.FinallyStatements.Add(New CodeCommentStatement("Handle any finally block statements."))
' A Visual Basic code generator produces the following Visual Basic source
' code for the preceeding example code:
' '------------------------------------------------------------------------------
' ' <auto-generated>
' ' This code was generated by a tool.
' ' Runtime Version:2.0.50727.42
' '
' ' Changes to this file may cause incorrect behavior and will be lost if
' ' the code is regenerated.
' ' </auto-generated>
' '------------------------------------------------------------------------------
'Option Strict Off
'Option Explicit On
' 'Namespace Samples
' Public Class TryCatchTest
' Public Sub New()
' MyBase.New()
' Try
' Me.ThrowApplicationException()
' Catch ex As System.ApplicationException
' 'Handle any System.ApplicationException here.
' Catch ex As System.Exception
' 'Handle any other exception type here.
' Finally
' 'Handle any finally block statements.
' End Try
' End Sub
' Private Sub ThrowApplicationException()
' Throw New System.ApplicationException("Test Application Exception")
' End Sub
' End Class
' End Namespace
开发者ID:VB.NET开发者,项目名称:System.CodeDom,代码行数:71,代码来源:CodeCatchClause
注:本文中的System.CodeDom.CodeCatchClause类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论