600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > throw在try中抛出异常 然后用catch捕捉并处理这个异常 同时catch也可以再次抛出这个异常...

throw在try中抛出异常 然后用catch捕捉并处理这个异常 同时catch也可以再次抛出这个异常...

时间:2022-06-12 03:03:08

相关推荐

throw在try中抛出异常 然后用catch捕捉并处理这个异常 同时catch也可以再次抛出这个异常...

using System;

public class ThrowTest

{

static void Main()

{

string s = null;

try

{

if (s == null)

{

throw new ArgumentNullException();

}

}

catch

{

s = "litao";

Console.WriteLine(s);

} Console.Write("The string s is null"); // not executed

}

}

//输出:

//litao

//The string s is null请按任意键继续 . . . 同上: // throw example

using System;

public class ThrowTest

{

static void Main()

{

string s = null;

try

{

if (s == null)

{

throw new ArgumentNullException();

}

}

catch

{

s = "litao";

Console.WriteLine(s);

throw ;//利用空throw语句,可以再次把已经捕获的异常抛出。

}

Console.Write("The string s is null"); // not executed

}

}

同上 // throw example

using System;

public class ThrowTest

{

static void Main()

{

string s = null;

try

{

if (s == null)

{

throw(new ArgumentNullException());

}

}

catch(ArgumentException exc)

{

s = "litao";

Console.WriteLine(s);

throw (exc); //等同throw exc;

//还等同 throw ;//利用空throw语句,可以再次把已经捕获的异常抛出。

//Console.WriteLine(exc.Message);

//Console.WriteLine(exc);

}

Console.Write("The string s is null"); // not executed

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。