C#怎么创建用户自定义异常(云服务器、云主机、高防IP、高防服务器、香港服务器、美国服务器,编程语言)

时间:2024-05-04 05:46:10 作者 : 石家庄SEO 分类 : 编程语言
  • TAG :

    C%23%E6%80%8E%E4%B9%88%E5%88%9B%E5%BB%BA%E7%94%A8%E6%88%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8

usingSystem;
namespaceUserDefinedException
{
classTestTemperature
{
staticvoidMain(string[]args)
{
Temperature temp=newTemperature();
try
{
temp.showTemp();
}
catch(TempIsZeroException e)
{
Console.WriteLine("TempIsZeroException: {0}", e.Message);
}
Console.ReadKey();
}
}
}
publicclassTempIsZeroException:ApplicationException
{
publicTempIsZeroException(stringmessage):base(message)
{
}
}
publicclassTemperature
{
inttemperature=0;
publicvoidshowTemp()
{
if(temperature==0)
{
throw(newTempIsZeroException("Zero Temperature found"));
}
else
{
Console.WriteLine("Temperature: {0}", temperature);
}
}
}

本文:C#怎么创建用户自定义异常的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:C#怎么实现当除以零时抛出异常下一篇:

16 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18