using System;
public class ThrowTest
{
static void Main()
{
string s = null;
try
{
if (s == null)
{
throw new ArgumentNullException();
}
}
catch
{
s = "litao";
Console.WriteLine(s);
}
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请按任意键继续 . . .
}
}
//输出:
//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
}
}
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
}
}
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
}
}