Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Delphi
EAbort = class(Exception);
procedure Abort;
  function ReturnAddr: Pointer;
  asm
          MOV     EAX,[EBP - 4]
  end;
begin
  raise EAbort.Create(SOperationAborted) at ReturnAddr;
end;

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 like this?
C#
try //application level try .. finally block
{
  try
  {
    ...
    try //Current level try .. finally block
    {
      ...
      // Throw a SilentException that will only catched by application level try .. finally block
      // and redirects execution to the end of application level try .. finally block
      Abort; //How to??????????????????????????
      ... 
    }
    catch 
    {
    }
  }
  catch 
  {
  }
}
catch ()
{
}
finally
{
}
...

Can anyone help me? Any suggestion wil be appropriate.
Thanks a lot. .
Posted
Comments
Sergey Alexandrovich Kryukov 31-Jan-13 1:06am    
Good idea, but the problem is already solved.
—SA

1 solution

It is already implemented: throw an exception and catch is in some location on some upper-level stack frame. This is all you need.

Now, you can define your custom exception, but one suitable declaration already exists: System.Threading.ThreadAbortException: http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception.aspx[^].

Not only you can use it for asynchronous thread abort (that is, from some other thread, by using Thread.Abort), but you can use it exactly for your purpose.

Problem solved.

[EDIT]

And of course, nothing like your inline assembly you (and me, too) gladly used with Delphi is applicable. CLR is very different: code is compiled into CIL (Common Intermediate Language), not CPU instructions. CPU comes into play when CIL is compiled with JIT. Please see:
http://en.wikipedia.org/wiki/Common_Intermediate_Language[^],
http://en.wikipedia.org/wiki/Just-in-time_compilation[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900