Repeating a function in C# until it no longer throws an exception

后端 未结 11 2079
一生所求
一生所求 2021-01-18 00:31

I\'ve got a class that calls a SOAP interface, and gets an array of data back. However, if this request times out, it throws an exception. This is good. However, I want m

11条回答
  •  生来不讨喜
    2021-01-18 01:04

    while(salesOrdersArray == null){
    
      try
      {
        salesOrdersArray = MagServ.salesOrderList(sessID, filter);
      }
      catch(salesOrderException e)
      {
         log(e.message);
      }
    }
    

    This will run forever, and is using exceptions as a loop which is slow. Is there a way you can modify your function that it returns null, instead of throwing an exception? If you're expecting that this call will fail regularly, don't use a try/catch block.

提交回复
热议问题