目前的例外情况 [英] Current Exception

查看:89
本文介绍了目前的例外情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点难以解释为什么我需要这个,所以我不会。现在考虑它是学术性的。


我想检测当前是否抛出异常,但我不能使用try语句。这个

不是我想做的,但这将证明我想做的事情:


尝试

抛出异常

终于{

Foo();

}

Foo(){

if(当前正在抛出/处理异常){

请稍等

}

}


我在上面的例子中意识到我可以使用catch,将其作为参数传递,并重新抛出。但是对于actaul

的情况我看着,我不能这样做,也无法获得捕获。


我看过StackTrace,但确实如此似乎没有拿到这些信息,除非我错过了

快速浏览一下。在德尔福,有一个全球的保存当前线程的当前异常。是否

.NET中的任何地方都有这样的东西,或以任何方式获得它?

-

Chad Z. Hower(又名Kudzu) ) - http://www.hower.org/Kudzu/

编程是一种反击的艺术形式


使你的ASP.NET应用程序运行得更快
http://www.atozed.com/IntraWeb/

解决方案




你可以做的是不处理异常然后委托

AppDomain.UnhandledException,这将执行函数你想要

然后它会回到你的代码。


希望这有帮助

SAlva
< br $>
-

Salvador Alvarez Patuel

Exony Ltd - 英国伦敦

" Chad Z. Hower aka Kudzu" ;写道:

有点难以解释为什么我需要这个,所以我不会。现在考虑它是学术性的。

我想检测当前是否抛出异常,但我不能使用try语句。这不是我想要做的,但这将证明我想做的事情:

最后抛出异常
最后{
Foo( );
}

Foo(){
if(当前正在抛出/处理异常){
请稍等
}
我知道在上面的例子中我会使用catch,将它作为参数传递,并重新抛出。但是对于我所看到的actaul
情况,我不能这样做,也无法获得捕获。

我看过StackTrace,但它似乎没有保留这些信息,除非我错过了它快速浏览一下。在德尔福,有一个全球的保存当前线程的当前异常。在.NET的任何地方都有这样的东西,或者以任何方式获得它吗?

-
Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/
编程是一种艺术形式反击

让你的ASP.NET应用程序运行得更快
http://www.atozed.com/IntraWeb/



" =?Utf-8?B?U2FsdmFkb3I = ?= QUOT; <萨****** @ discussions.microsoft.com>写在

新闻:5F ********************************** @ microsof t .com:

你可以做的是不处理异常然后委托
AppDomain.UnhandledException,这将执行你想要的功能然后它会回来你的代码。




谢谢,但不会工作。我不能使用一个事件,我需要从内联代码确定。


我也不能设置一个标志,因为它的线程(可能找到某种方式跟踪可能)但是

更大的问题是我怀疑它就像Delphi的异常处理程序一样,它发生在所有代码之后

将它发送到外层,所以它会发生在我的代码之后执行。

-

Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/

编程是一种反击的艺术形式

在更短的时间内更轻松地开发ASP.NET应用程序:
http ://www.atozed.com/IntraWeb/


您可以创建自己的全局广告吗?变量(某个类的静态成员)

并在捕获异常时自己设置它(它必须被捕获

某处...)

然后在你实际处理它的任何代码中,你可以检查

静态成员(并在完成后将其设置为null?)


- -

Adam Clauss


" Chad Z. Hower aka Kudzu" < CP ** @ hower.org>在消息中写道

news:Xn ************************** @ 127.0.0.1 ...

" =?Utf-8?B?U2FsdmFkb3I =?=" <萨****** @ discussions.microsoft.com>在
新闻中写道:5F ********************************** @ microsof t.com:< blockquote class =post_quotes>你可以做的是不处理异常然后委托
AppDomain.UnhandledException,这将执行你想要的功能,然后它将返回到你的代码。



谢谢,但不会工作。我不能使用一个事件,我需要从
内联代码确定。

我也不能设置一个标志,因为它的线程(可以找到某种方式跟踪或许跟踪)但是更大的问题是我怀疑它就像Delphi的异常处理程序一样,它发生在所有代码发布到外层之后,所以它会发生在我的代码之后执行。

-
Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/
编程是一种反击的艺术形式

更容易开发ASP.NET应用程序在更短的时间内:
http://www.atozed.com/IntraWeb/



Its a bit tough to explain why I need this, so I wont. Consider it academic for now.

I would like to detect if an exception is currently being thrown, but I cannot use a try statement. This
is not what I want to do, but this will demonstrate what I want to do:

try
throw exception
finally {
Foo();
}
Foo() {
if (An Exception is currently being thrown/handled) {
Do sometihng
}
}

I realize in the above case I coudl use catch, pass it as an argument, and re throw. But for the actaul
situation Im looking at, I cannot do that and will not have access to a catch.

Ive looked at StackTrace, but it does not seem to hold this information either unless Ive missed it on
quick glance. In Delphi there is a "global" that holds the current exception for the current thread. Is
there anything like this anywhere in .NET, or any way to obtain it?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/

解决方案

Hi,

What you can do is not to handle to exception and then delegate
AppDomain.UnhandledException, this will execute the function that you want
and then it will go back to your code.

Hope this helps
SAlva

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Chad Z. Hower aka Kudzu" wrote:

Its a bit tough to explain why I need this, so I wont. Consider it academic for now.

I would like to detect if an exception is currently being thrown, but I cannot use a try statement. This
is not what I want to do, but this will demonstrate what I want to do:

try
throw exception
finally {
Foo();
}
Foo() {
if (An Exception is currently being thrown/handled) {
Do sometihng
}
}

I realize in the above case I coudl use catch, pass it as an argument, and re throw. But for the actaul
situation Im looking at, I cannot do that and will not have access to a catch.

Ive looked at StackTrace, but it does not seem to hold this information either unless Ive missed it on
quick glance. In Delphi there is a "global" that holds the current exception for the current thread. Is
there anything like this anywhere in .NET, or any way to obtain it?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/



"=?Utf-8?B?U2FsdmFkb3I=?=" <Sa******@discussions.microsoft.com> wrote in
news:5F**********************************@microsof t.com:

What you can do is not to handle to exception and then delegate
AppDomain.UnhandledException, this will execute the function that you
want and then it will go back to your code.



Thanks, but wont work. I cant use an event, I need to determine from inline code.

I cant set a flag either, because its threaded (Which could find some way to track maybe) but the
bigger issue is that I suspect its like Delphi''s exception handler, it happens AFTER all the code has
made it out to the outer levels so it would happen after my code executed.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/


Could you create your own "global" variable (a static member of some class)
and set it yourself when the catch the exception (it HAS to be caught
somewhere...)
Then in whatever code you are actually handling it, you can check that
static member (and set it to null when done?)

---
Adam Clauss

"Chad Z. Hower aka Kudzu" <cp**@hower.org> wrote in message
news:Xn**************************@127.0.0.1...

"=?Utf-8?B?U2FsdmFkb3I=?=" <Sa******@discussions.microsoft.com> wrote in
news:5F**********************************@microsof t.com:

What you can do is not to handle to exception and then delegate
AppDomain.UnhandledException, this will execute the function that you
want and then it will go back to your code.



Thanks, but wont work. I cant use an event, I need to determine from
inline code.

I cant set a flag either, because its threaded (Which could find some way
to track maybe) but the
bigger issue is that I suspect its like Delphi''s exception handler, it
happens AFTER all the code has
made it out to the outer levels so it would happen after my code executed.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/



这篇关于目前的例外情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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