throw在try中抛出异常,然后用catch捕捉并处理这个异常,同时catch也可以再次抛出这个异常
2007-04-05 01:34
731 查看
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
}
}
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
}
}
相关文章推荐
- throw在try中抛出异常,然后用catch捕捉并处理这个异常,同时catch也可以再次抛出这个异常
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗
- JAVA 语言如何进行异常处理,关键字:throws,throw,try,catch,finally 分别代表什么意义?在 try 块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- 【Java面试题】22 JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- Java try-catch-finally进行异常处理以及throw主动抛出异常
- 错误处理try-catch,异常抛出throws、throw
- Android:java 抛出异常throw与throws以及捕捉异常try、catch、finally学习
- 异常概念和处理机制,try-catch-finally,throw和throws,自定义异常
- Java语言如何进行异常处理,关键字:throws、throw、try、catch、finally分别如何使用?
- C++异常处理:try,catch,throw,finally的用法
- Java异常处理之throw, throws,try和catch
- 关于java异常处理的几个关键字 try catch/throw/throws
- 22 C#中的异常处理入门 try catch throw
- C++中异常处理的语法 try catch throw