Setting the message of a custom Exception without passing it to the base constructor

后端 未结 5 1282
悲&欢浪女
悲&欢浪女 2021-02-11 12:20

I want to make a custom Exception in C#, but in theory I do need to do a little parsing first before I can make a human readable ExceptionMessage.

The problem is that th

5条回答
  •  花落未央
    2021-02-11 12:41

    What's wrong with something like this.

        public class FolderNotEmptyException : Exception
    {
    
        public FolderNotEmptyException(string Path) : base($"Directory is not empty. '{Path}'.")
        { }
    
        public FolderNotEmptyException(string Path, Exception InnerException) : base($"Directory is not empty. '{Path}'.", InnerException)
        { }
    
    }
    

    I just use a string and include parameters. Simple solution.

提交回复
热议问题