在布尔方法C#中返回异常

Vee*_*era -1 c# boolean-logic exception

以下是解释我的问题的代码示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Program.Sample();
                Console.ReadLine();
            }
            catch (Exception)
            {
                Console.WriteLine("InvalidOperation Exception");
            }
        }

        static bool Sample()
        {
            int a = 1; int b = 2;
            if (a == b) //Some Condition checking
            {
                return true;
            }
            else
            { //Is this Proper returning Exception In Boolean method instead of False
                throw new InvalidOperationException();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在客户端应用程序中捕获此异常并显示消息,我想知道这是否是正确的方法?

Ned*_*nov 5

当发生异常情况或遇到使用错误时,应抛出异常,即null参数。在您的情况下,最好只返回return false