错误处理 - 自定义“投掷”? [英] Error Handling - custom "Throw"?

查看:67
本文介绍了错误处理 - 自定义“投掷”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这里创建一个这样的自定义错误处理程序。
VB.NET:


....

尝试

...

投掷(贷方名称不在表格中)

....


catch(贷款人姓名不在表格中)

''处理激活,提供好用户留言等。

catch

结束尝试


在VB.NET中是这样的吗?


注意错误不是一个.NET暴露的标准例外情况

因此没有明显的方法可以捕获

。该错误与应用程序的业务逻辑有关。 (我

不知道是否可以转到一个捕获条款 - 但我不会想要以这种方式对它进行编码)。

TIA,


比尔

解决方案

比尔,


肯定是!!只需创建一个派生自异常的类...


''===

公共类LenderNameException

继承异常


Public Sub New()

MyBase.New()

End Sub


公共子新(ByVal消息为字符串)

MyBase.New(消息)

结束子


结束班级

''===


然后......


..

..

..

尝试

...

抛出新的LenderNameException(&Hurray) !!")

...

Catch ex作为LenderNameException

...

结束尝试< br $>
..

..

..


-

HTH,

- Tom Spink,überGeek


请回复新闻组,

所以所有人都可以受益


" System.Reflection Master"


====转换为2002 ====

删除内联声明


" bill salkin" <一个******* @ discussions.microsoft.com>在消息中写道

news:01 **************************** @ phx.gbl ... < blockquote class =post_quotes>我想在VB.NET中创建一个这样的自定义错误处理程序:

...
尝试
。 ..
投掷(贷方名称不在表格中)
....

捕获(贷方名称不在表格中)
''处理繁琐,提出好用户留言等等。
结束尝试

在VB.NET中有类似的东西吗?

请注意该错误不是.NET暴露的标准异常之一,因此没有明显的方法可以捕获它。该错误与应用程序的业务逻辑有关。 (我不知道是否可以转到一个捕获条款 - 但我不想这样编码)。

TIA ,

Bill



" bill salkin" <一个******* @ discussions.microsoft.com> schrieb

我想在VB.NET中创建一个这样的自定义错误处理程序:

...
试试
...
投掷(贷方名称不在表格中)
....

catch(贷方名称不在表格中)
''处理重复,提出好的用户消息等等。
结束尝试

在VB.NET中是否可以这样?

请注意,错误不是.NET暴露的标准异常之一,因此没有明显的方法可以捕获它。该错误与应用程序的业务逻辑有关。 (我不知道是否可以转到一个catch子句 - 但我不想这样编码)。



编写自己派生自System.Exception的类。

-

Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


*" bill salkin" <一个******* @ discussions.microsoft.com> scripsit:

我想在VB.NET中创建一个这样的自定义错误处理程序:

...
尝试
...
投掷(贷方名称不在表格中)
....

catch(贷方名称不在表格中)
''处理excpetion,提供好用户留言等等。
结束尝试

在VB.NET中是否可以这样?
请注意,错误不是.NET暴露的标准异常之一,因此没有明显的方法可以捕获它。该错误与应用程序的业务逻辑有关。 (我不知道是否可以转到一个catch子句 - 但我不想这样编码)。


< br $>
\\\

公共类FooException

继承异常


Public Sub New( ......)


I''d like to create a custom error handler like this in
VB.NET:

....
try
...
Throw ("Lender Name not in table")
....

catch ("Lender Name not in table")
'' handle excpetion, put up nice user message, etc.
catch
end try

Is something like that possible in VB.NET?

Note that the error is not one of the standard exceptions
that .NET exposes so there is no obvious way to "catch"
it. The error relates to the business logic of the app. (I
don''t know if one can "goto" a catch clause -- but I don''t
want to code it that way).
TIA,

Bill

解决方案

Hi Bill,

It certainly is!! Just create a class that derives from "Exception"...

'' ===
Public Class LenderNameException
Inherits Exception

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal Message As String)
MyBase.New(Message)
End Sub

End Class
'' ===

and then...

..
..
..
Try
...
Throw New LenderNameException("Hurrah!!")
...
Catch ex As LenderNameException
...
End Try
..
..
..

--
HTH,
-- Tom Spink, über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations

"bill salkin" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...

I''d like to create a custom error handler like this in
VB.NET:

...
try
...
Throw ("Lender Name not in table")
....

catch ("Lender Name not in table")
'' handle excpetion, put up nice user message, etc.
catch
end try

Is something like that possible in VB.NET?

Note that the error is not one of the standard exceptions
that .NET exposes so there is no obvious way to "catch"
it. The error relates to the business logic of the app. (I
don''t know if one can "goto" a catch clause -- but I don''t
want to code it that way).
TIA,

Bill



"bill salkin" <an*******@discussions.microsoft.com> schrieb

I''d like to create a custom error handler like this in
VB.NET:

...
try
...
Throw ("Lender Name not in table")
....

catch ("Lender Name not in table")
'' handle excpetion, put up nice user message, etc.
catch
end try

Is something like that possible in VB.NET?

Note that the error is not one of the standard exceptions
that .NET exposes so there is no obvious way to "catch"
it. The error relates to the business logic of the app. (I
don''t know if one can "goto" a catch clause -- but I don''t
want to code it that way).


Write your own class derived from System.Exception.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


* "bill salkin" <an*******@discussions.microsoft.com> scripsit:

I''d like to create a custom error handler like this in
VB.NET:

...
try
...
Throw ("Lender Name not in table")
....

catch ("Lender Name not in table")
'' handle excpetion, put up nice user message, etc.
catch
end try

Is something like that possible in VB.NET?

Note that the error is not one of the standard exceptions
that .NET exposes so there is no obvious way to "catch"
it. The error relates to the business logic of the app. (I
don''t know if one can "goto" a catch clause -- but I don''t
want to code it that way).



\\\
Public Class FooException
Inherits Exception

Public Sub New(...)


这篇关于错误处理 - 自定义“投掷”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆