try-catch blocks with the return type

后端 未结 11 1940
半阙折子戏
半阙折子戏 2021-02-07 14:02

If I have a method that returns something, like

public DataTable ReturnSomething()
{
   try
   {  
      //logic here
     return ds.Tables[0];
   }
   catch (Ex         


        
11条回答
  •  一生所求
    2021-02-07 14:56

    i'd assume you can still set the message, then return null or whatever the c# equivalent is

    public DataTable ReturnSomething(){ 
       try {
            //logic here 
            return ds.Tables[0]; 
       } catch (Exception e) {
            ErrorString=e.Message;
            return null;
       }
    }
    

提交回复
热议问题