creating my own exceptions c#

后端 未结 4 1663
萌比男神i
萌比男神i 2020-12-24 07:43

Following examples in my C# book and I came across a book example that doesn\'t work in Visual Studio. It deals with creating your own exceptions, this one in particular is

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 08:04

    Since .NET 3.0 custom exceptions should be derived from Exception and not ApplicationException, so use this:

    public class NegativeNumberException : Exception
    { 
        public NegativeNumberException():base() { } 
        public NegativeNumberException (string message): base(message) { }
    }
    

提交回复
热议问题