6.1.txt

来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 27 行

TXT
27
字号
Listing 6.1 Using a try/catch Block to Handle Exceptions
using System;
namespace _1_TryCatch
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
// ask for and read a number from the user
Console.Write( “Enter a number: “);
int input = Int32.Parse( Console.ReadLine() );
// the last iteration in this loop will attempt to
// divide by zero
for( int i = 5; i >= 0; i— )
Console.WriteLine( “{0}/{1}={2}”, input, i, input/i );
}
catch( Exception e )
{
// display exception message
Console.WriteLine( “An error occurred: {0}”, e.Message );
}
}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?