Home > database >  .NET Core How to see posible errors method can throw
.NET Core How to see posible errors method can throw

Time:10-09

Maybe it is silly question, but where can I find possible errors method can throw? It's often necessary to know in which cases method can throw an error and it would be great to quickly know which ones. Mostly I'm interesting in .NET Core libraries. Thank you

CodePudding user response:

A method in a well written library should document all the possible exceptions that may be thrown from it.

For example

/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
public static string AddQueryString(string uri, string name, string value)
{
   if (uri == null)
   {
      throw new ArgumentNullException(nameof(uri));
   }

   if (name == null)
   {
       throw new ArgumentNullException(nameof(name));
   }

   if (value == null)
   {
        throw new ArgumentNullException(nameof(value));
   }

   //more code
}

The above snippet is taken from the aspnetcore source code

  • Related