How to validate format for string.Format method

后端 未结 4 813
感情败类
感情败类 2021-02-14 05:15

string.Format has following method signature

string.Format(format, params, .., .. , ..);

I want to pass custom format each time like



        
4条回答
  •  忘了有多久
    2021-02-14 05:58

    You can validate with try catch, if format throw exceptin you log information and stop treatment.

    try 
    { 
       string.Format(custFormat, params, .., .. , ..);
    }
    catch(FormatException ex)  
    { 
      throw ex;
    }
    
    string message = ProcessMessage(custFormat, name);
    

提交回复
热议问题