Removing excessive try-catch blocks

前端 未结 8 2388
Happy的楠姐
Happy的楠姐 2021-02-14 19:10

I\'m refactoring a medium-sized WinForms application written by other developers and almost every method of every class is surrounded by a try-catch block. 99% of t

8条回答
  •  一向
    一向 (楼主)
    2021-02-14 19:38

    we can remove try and catch by adding condition Like

     string emailAddresses = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
            if (!Regex.IsMatch(Email, emailAddresses))
            {
                throw new UserFriendlyException($"E-mail Address Is not Valid");
            }**strong text**
    

提交回复
热议问题