C# try {} catch {}

后端 未结 11 2418
既然无缘
既然无缘 2021-02-08 10:51

hi and thanks for reading. im a newbie in programming and C# and sockets programming. in my code i try and catch problems to provide fault tolarence in my app. the following:

11条回答
  •  北恋
    北恋 (楼主)
    2021-02-08 11:19

    I actually just read a blog post on this very topic this morning.

    You could do something like mentioned in the comments of the post:

    catch(Exception e){
        if(    e is ArgumentNullException 
            || e is EncoderFallbackException 
            || e is ...whatever 
        ){
          OnNetworkEvents eventArgs = new OnNetworkEvents("Network Unavailable", e.Message);
          OnUpdateNetworkStatusMessage(this, eventArgs);
        } else { throw; } 
    }
    

提交回复
热议问题