【c#】try...catch...finally
来源:互联网 发布:yy摇骰子软件 编辑:程序博客网 时间:2024/05/29 12:31
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace unit7
{
class Program
{
enum Orientation : byte
{
North = 1,
South = 2,
East = 3,
West = 4
}
static void Main(string[] args)
{
//Debug.WriteLine("debug");
//Trace.WriteLine("trace");
//Console.WriteLine("hello world");
//Console.ReadKey();
//练习4
Orientation myDirection;
for (byte myByte = 2; myByte < 10; myByte++)
{
try
{
myDirection = checked((Orientation)myByte);
if (myByte < 1 || myByte > 10)
{
throw new ArgumentOutOfRangeException("myByte", myByte, "Value must between 1 and 4");
}
}
catch(ArgumentOutOfRangeException e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Assigning default value, Orientation.North");
myDirection = Orientation.North;
}
finally
{
Console.WriteLine("finally");
}
Console.WriteLine(myDirection);
}
Console.ReadKey();
}
}
}
阅读全文
0 0
- 【c#】try...catch...finally
- try..catch..finally
- try-catch-finally
- Try-catch-finally机制
- 关于try-catch-finally
- C# try catch finally
- try...catch...finally
- try catch finally用法
- Try ---Catch----Finally
- try...catch... finally
- try....catch...finally 妙用
- try{} catch(){}finally{}执行
- Try Catch Finally
- try-catch-finally
- C# try, catch ,finally
- try catch finally
- try catch finally
- try-catch-finally
- 决策树判断图像是否为广告
- 结构算法 003 单链表的查找算法
- js判断变量是否未定义的代码
- 文章标题
- IntelliJ new project
- 【c#】try...catch...finally
- 腾讯前端求职训练营第一天
- 文章标题
- (by王垠)如何掌握所有的程序语言
- 【c#】面向对象简介(构造、析构函数,静态构造函数、静态类)
- haproxy打印日志到rsyslog
- C++实现本地进程通信
- 打开网页就自动打开qq聊天的对话框的办法:使用iframe
- SQL Developer 远程连接 Oracle