c语言宏定义####
C#用户定义的异常 (C# User-defined exceptions)
In C#, we can create our exception class by inheriting base class Exception. Because as we know that Exception is the base class for all types of exceptions in C#.
在C#中,我们可以通过继承基类Exception来创建异常类 。 因为我们知道Exception是C#中所有类型的异常的基类。
Here is the example of a user-defined exception,
这是用户定义的异常的示例,
using System;
class UserDefineException: Exception
{
public UserDefineException(string str)
{
Console.WriteLine(str);
}
}
class Program
{
static void Main()
{
UserDefineException M = new UserDefineException("User Define Exception");
try
{
throw M;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Output
输出量
User Define Exception
Exception of type 'UserDefineException' was thrown.
In the above program, we created a class "UserDefineException" by inheriting the base class "Exception" and created a parameterized constructor, through the user-defined object in "try block" of "Program" class, it is caught in "catch block".
在上面的程序中,我们通过继承基类“ Exception”创建了一个“ UserDefineException”类,并通过“ Program”类的“ try块”中的用户定义对象创建了一个参数化构造函数,将其捕获在“ catch块”中“ 。
Read more:
阅读更多:
翻译自: https://www.includehelp.com/dot-net/user-defined-exceptions-in-csharp.aspx
c语言宏定义####