How to use Java-style throws keyword in C#?

前端 未结 10 2162
说谎
说谎 2020-11-27 04:39

In Java, the throws keyword allows for a method to declare that it will not handle an exception on its own, but rather throw it to the calling method.

Is there a sim

10条回答
  •  情深已故
    2020-11-27 05:15

    You are asking about this :

    Re-throwing an Exception

    public void Method()
    {
      try
      {
          int x = 0;
          int sum = 100/x;
      }
      catch(DivideByZeroException e)
      {
          throw;
      }
    }
    

    or

    static void Main() 
        {
            string s = null;
    
            if (s == null) 
            {
                throw new ArgumentNullException();
            }
    
            Console.Write("The string s is null"); // not executed
        }
    

提交回复
热议问题