none
How to retry last statement in try{}catch{} block? RRS feed

  • Question

  • Hi,

    I have following code

    try{

    Someobject.Execute()
    }

    catch (SomeException)

    {

    }

    I'd like to retry Someobject.Execute in case SomeException is thrown, how can I do that?

    Thursday, June 29, 2006 3:21 PM

Answers

  • Put it inside a loop.  Something like:

    for (int ix=0;;++ix) {
      try {
        Someobject.Execute();
        break;
      }
      catch (SomeException) {
        if (ix > MAXTRIES) throw Exception("I give up");
        DoSomethingToMakeExecuteWork();
      }
    }

    Thursday, June 29, 2006 3:46 PM
    Moderator

All replies

  • Put it inside a loop.  Something like:

    for (int ix=0;;++ix) {
      try {
        Someobject.Execute();
        break;
      }
      catch (SomeException) {
        if (ix > MAXTRIES) throw Exception("I give up");
        DoSomethingToMakeExecuteWork();
      }
    }

    Thursday, June 29, 2006 3:46 PM
    Moderator
  • I want to return to back to Someobject.Execute() if exception handled.
    Thursday, June 29, 2006 4:52 PM
  • It is handled when it executes through the catch {} block.

    Thursday, June 29, 2006 5:02 PM
    Moderator