Await in catch block

前端 未结 9 1495
醉梦人生
醉梦人生 2020-11-28 11:14

I have the following code:

WebClient wc = new WebClient();
string result;
try
{
  result = await wc.DownloadStringTaskAsync( new Uri( \"http://badurl\" ) );
         


        
9条回答
  •  佛祖请我去吃肉
    2020-11-28 11:26

    In a similar instance, I was unable to await in a catch block. However, I was able to set a flag, and use the flag in an if statement (Code below)

    ---------------------------------------...

    boolean exceptionFlag = false; 
    
    try 
    { 
    do your thing 
    } 
    catch 
    { 
    exceptionFlag = true; 
    } 
    
    if(exceptionFlag == true){ 
    do what you wanted to do in the catch block 
    }
    

提交回复
热议问题