using System;
using System.Collections.Generic;
using System.Text;
namespace V7._引发异常
{
class Program
{
private static int ConvertStringToInt(string mystr) {
int outnum = 0;
try
{
outnum = Convert.ToInt32(mystr );
return outnum;
}
catch {
//异常提示
throw new FormatException("格式转换不正确");
}
}
static void Main(string[] args)
{
string mystr = "51zz";
try
{
int myint;
myint = Program.ConvertStringToInt(mystr);
Console.WriteLine(myint);
}
catch (FormatException exf){
Console.WriteLine(exf.Message.ToString ());
}
Console.ReadKey();
}
}
}
联系客服