广州万户网站公司,优化方案语文,软件定制开发多少钱,全flash 电子商务网站如何推广这是一个用英语写的try-catch例子
简单来说就是一个try#xff0c;try里面的代码可能会出错#xff0c;然后有两个catch#xff0c;规定了具体的错误是什么
如果发生相应的错误#xff0c;就会把错误信息存到err里#xff0c;err.Message是一个字符串格式的提示信息try里面的代码可能会出错然后有两个catch规定了具体的错误是什么
如果发生相应的错误就会把错误信息存到err里err.Message是一个字符串格式的提示信息可以打印出来。
最后用catchException可以捕捉大部分错误。
finally部分是无论代码出错与否都会执行的 简单来说就是我的代码在try里面出的错可以被catch捕捉到然后跳转到catch的代码位置继续执行。
using System;class Program
{static void Main(){Console.WriteLine(请输入一个数字);string userinputConsole.ReadLine();try{int num Convert.ToInt32(userinput);Console.WriteLine(input is num);}catch(FormatException err){Console.WriteLine(err.Message);}catch (OverflowException err){Console.WriteLine(err.Message);}catch(Exception err){Console.WriteLine(err.Message);}finally{Console.WriteLine(Finish);}}
}
输出结果
请输入一个数字
jjgjg
The input string jjgjg was not in a correct format.
Finish