title: getting error not all code paths return value by c# compiler
body: <p>This is a basic string reverse program and I want to do some level of exception handling in it. But during compilation it gives me an error "NOt all code paths return value. I am not able to find out why</p>
  
  <pre><code> public static string Reverse(string s)
          {
              try
              {
                  if (string.IsNullOrEmpty(s))
                  {
                      throw new NullReferenceException();
                  }
  
                  char[] c = s.ToCharArray();
                  int start = 0;
                  int end = c.Length - 1;
                  char temp;
  
                  while (start &lt; end)
                  {
                      temp = c[start];
                      c[start] = c[end];
                      c[end] = temp;
                      start++;
                      end--;
                  }
                  return new string(c);
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
              }
          }
  </code></pre>
  
  <p>Thanks guys...I change the code to something like this</p>
  
  <pre><code> public static string Reverse(string s)
          {
              if (!string.IsNullOrEmpty(s))
              {
                  char[] c = s.ToCharArray();
                  int start = 0;
                  int end = c.Length - 1;
                  char temp;
  
                  while (start &lt; end)
                  {
                      temp = c[start];
                      c[start] = c[end];
                      c[end] = temp;
                      start++;
                      end--;
                  }
                  return new string(c);
              }
              else return s;
  
  
          }
  </code></pre>