⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6.3.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 6.3 Displaying Exception Information
using System;
namespace _3_ExceptionInfo
{
class Class1
{
// outputs information about an exception
static void DisplayExceptionInformation( Exception e )
{
Console.WriteLine( “Application: {0}”, e.Source );
Console.WriteLine( “Method: {0}”, e.TargetSite );
Console.WriteLine( “Message: {0}”, e.Message );
Console.WriteLine( “Call Stack: {0}”, e.StackTrace );
if( e.HelpLink != null )
Console.WriteLine( “Help Link: {0}”, e.HelpLink );
}
// displays a menu and asks user for input
static int DisplayMenu()
{
int input = 0;
Console.WriteLine( “1) Throw a system exception” );
Console.WriteLine( “2) Throw an application exception” );
Console.WriteLine( “3) Quit” );
Console.Write( “Enter command: “ );
try
{
// get input from user
input = Int32.Parse( Console.ReadLine() );
}
catch
{
Console.WriteLine( “Invalid Input. Try again.\n” );
return DisplayMenu();
}
return input;
}
[STAThread]
static void Main(string[] args)
{
int input = DisplayMenu();
while( input != 3 )
{
// throw exception and display exception information
try
{
switch( input )
{
case 1:
{
throw new SystemException();
}
case 2:
{
throw new ApplicationException();
}
default:
}
}
catch( ApplicationException e )
{
Console.WriteLine( “An application exception occurred:” );
DisplayExceptionInformation( e );
}
catch( SystemException e )
{
Console.WriteLine( “A system exception occurred:” );
DisplayExceptionInformation( e );
}
catch( Exception e )
{
Console.WriteLine( “An unknown error occurred:” );
DisplayExceptionInformation( e );
}
input = DisplayMenu();
}
}
}
}

⌨️ 快捷键说明

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