我是JavaScript新手,但一般不熟悉编程/脚本,我有一个关于throw
例外的查询。
所以,我想知道的是throw
异常是否有一种else
语句
如
// More code above
try
{
if(i=="something") {
throw "'i' equals 'something'."
}
else
{
throw "'i' doesn't equal 'something'."
}
}
// More code here
这样的事情可能吗?
您可能正在寻找finally
关键字
try
{
if(i=="something") {
throw "'i' equals 'something'."
}
else
{
throw "'i' doesn't equal 'something'."
}
} catch( ex ) {
// your exception handling code
} finally {
// Statements that are executed after the try statement completes.
}
演示:http://jsfiddle.net/7y6Hz/