您的位置:首页 > 编程语言 > C#

C#异常在catch语句中默认处理

2013-05-05 18:15 375 查看
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.IO;
using System.Text;
using System.Drawing;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
class Program
{
static string GetHtml(string url)
{

string html = string.Empty;
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Timeout=20*1000;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s,Encoding.Default);
html = sr.ReadToEnd();
return html;
}
static void Main(string[] args)
{

try
{
Operation();

}
catch (Exception ex)
{

Console.WriteLine(ex.Message);
}
Console.ReadKey();
}

private static void Operation()
{
try
{
int numberA = Convert.ToInt32(Console.ReadLine());
int numberB = Convert.ToInt32(Console.ReadLine());
int result = numberA / numberB;
Console.WriteLine("结果:" + result);

}
catch (Exception ex)
{
throw;//注意如果写上throw说明将捕获到的异常再次抛给调用函数,如果不写,则说明异常已经默认处理
}
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: