C#异常的代码,大虾帮我解释一下,我初学

来源:百度知道 编辑:UC知道 时间:2024/06/14 22:57:21
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace haha
{
class Program
{
public class UserEmployeeException: Exception
{
private string errorinfo=string.Empty;
public UserEmployeeException()
{
}
public UserEmployeeException (string message) : base(message)
{
errorinfo = message;
}

public UserEmployeeException (string message, Exception
inner):base(message,inner)
{
errorinfo = message;
inner = null;
}
}
public static void Main()
{
try
{
throw new UserEmployeeException("error Info of use ");

继承自 Exception 而已,没什么特别的东西啊

声明一个UserEmployeeException自定义异常类,它继承自Exception,通过构造函数将错误信息储存起来
程序运行时在try块中抛出一个声明好的UserEmployeeException异常,带上构造函数参数“error Info of use”这个错误信息,异常被catch捕捉,显示出错误信息“error Info of use”

UserEmployeeException自定义异常类

就是写了个异常类,然后把出错信息保持在异常类里面了~