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说明将捕获到的异常再次抛给调用函数,如果不写,则说明异常已经默认处理 } } } }
相关文章推荐
- c#描述异常处理语句try、catch、finally执行时的相互关系
- c#描述异常处理语句try、catch、finally执行时的相互关系
- c#描述异常处理语句try、catch、finally执行时的相互关系
- C# .net编程基础-try-catch异常处理-阶乘示例
- C#学习使用try-catch-finally错误处理表达式(续)--定义自己的异常消息类
- 【c#】异常处理:try catch throw
- 学习笔记之C#类、循环中的语句、基础知识和异常处理
- WCF基础教程之异常处理:你的Try..Catch语句真的能捕获到异常吗?
- 黑马程序员----C#中的流程控制语句之异常处理语句
- C#2继承、foreach语句及异常处理语句
- 关于异常处理语句catch和finally的执行先后顺序
- C# 语句异常处理语句
- 【C++】try 语句捕获异常,catch子句处理异常
- Java异常处理之try...catch...语句的使用进阶
- 描述异常处理语句try、catch、finally执行时的相互关系
- 描述异常处理语句try、catch、finally执行时的相互关系
- JS异常处理try..catch语句的作用和实例
- 22 C#中的异常处理入门 try catch throw
- 使用try...catch语句处理异常
- Swift中使用do-catch语句进行异常处理