csharp C#异常TRY和CATCH

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp C#异常TRY和CATCH相关的知识,希望对你有一定的参考价值。

int age;
try
{
 age = int.Parse(ageString);
 Console.WriteLine("Thank you");
}
catch (Exception e)
{
 // Get the error message out of the exception
 Console.WriteLine(e.Message);
}



The catch now looks like a method call, with the Exception e being a parameter to
the method. This is exactly how it works. Within the catch clause the value of e is set
to the exception that was thrown by Parse. The Exception type has a property called
Message which contains a string describing the error. If a user types in an invalid
string the program above will write the text in the exception, which contains the
message:

Input string was not in a correct format.


This message is obtained from the exception that was thrown. This is useful if the code
inside the try block could throw several different kinds of exception, since it means
that the message reflects what has actually hap

以上是关于csharp C#异常TRY和CATCH的主要内容,如果未能解决你的问题,请参考以下文章

csharp 有关如何使用try catch构造捕获异常的示例。从计算机编程基础与C#http://www.introprogr

try-catch语句

水能详细讲解一下java 中的异常处理 try catch throw

csharp C#使用TRY捕获异常

Objective-C try/catch异常处理机制原理。

VC++异常捕获__try...__except和try...catch的使用介绍(附源码)