如何编写Delphi的“abort”的c#版本程序 [英] How to write c# version of Delphi's "Abort" procedure

查看:112
本文介绍了如何编写Delphi的“abort”的c#版本程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi有一个名为Abort的程序。以下内容摘自Delphi帮助:

使用Abort从执行路径中逃脱而不报告错误.Abort引发一个特殊的静默异常 (EAbort),其运行方式与任何其他异常类似,但不向最终用户显示错误消息。中止将执行重定向到最后一次尝试的结束..最后阻止。

我现在要去.Net。我找不到任何方法类似于中止程序。是否可以编写Delphi'的Abort程序的c#版本?

任何人都可以帮助我吗?任何建议都是合适的。

非常感谢。

Delphi has a precedure named "Abort".The following is picked up from Delphi help:
Use Abort to escape from an execution path without reporting an error.Abort raises a special "silent exception" (EAbort), which operates like any other exception, but does not display an error message to the end user. Abort redirects execution to the end of the last try .. finally block.
I''m now going to .Net. I can not find any method Similar to the "Abort" procedure.Is it possible to to write c# version of Delphi''s "Abort" procedure?
Can anyone help me? Any suggestion wil be appropriate.
Thanks a lot.

推荐答案

我不知道,但有一个解决方法。试试这个。



创建你自己的自定义异常 -



Not that I know of, but there is a workaround for that. Try this.

Create your own custom exception-

public class DelphiLikeSilentException: Exception
{
}



从代码中抛出异常,你需要像''Abort''程序那样的delphi

写一个空的catch块来处理DelphiLikeSilentException




Throw that exception from your code where you need the delphi like ''Abort'' procedure
Write a empty catch block to handle DelphiLikeSilentException

try
{
//Some code here
throw new DelphiLikeSilentException();
//Other code
}
catch(DelphiLikeSilentException)
{
}
//other catch blocks if needed
finally
{
//More code here
}


这篇关于如何编写Delphi的“abort”的c#版本程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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