在js中是否有象try catch这样的异常捕捉机制
解决方案 »
- asp.net怎么把二维数组存到session中,怎么把session值读取并赋值给新二维数组
- 怎么在远处服务机器里面 登录软件的时候 获取到远程登录用户名以及ip
- 页面传值除了response.redirect,还有什么
- 100!分 关于怎么见后台的问题!
- .net中怎么处理换行,回车的问题
- 如何删除服务器文件,急!!!
- 考试系统我用javascript做了计时功能,但是我的考试功能是用C#.NET写的代码,怎么把它们结合起来?
- 泛型求猪???
- asp.net图片错位,在线等。。。。。
- #######跪求,microsoft office spreadsheet的excle的c#导如数据,编辑,保存的原码资料 100送!!!!
- 怎样获取gridview的总数据数?
- 一个Remoting中的实体序列化问题
try
{}
catch(e)
{}
finally
{}
The TRy/catch/finally statement is JavaScript's exception-handling mechanism. The TRy clause of this statement simply defines the block of code whose exceptions are to be handled. The try block is followed by a catch clause, which is a block of statements that are invoked when an exception occurs anywhere within the TRy block. The catch clause is followed by a finally block containing cleanup code that is guaranteed to be executed, regardless of what happens in the try block. Both the catch and finally blocks are optional, but a try block must be accompanied by at least one of these blocks. The TRy, catch, and finally blocks all begin and end with curly braces. These braces are a required part of the syntax and cannot be omitted, even if a clause contains only a single statement. Like the tHRow statement, the try/catch/finally statement is standardized by ECMAScript v3 and implemented in JavaScript 1.4.The following code illustrates the syntax and purpose of the TRy/catch/finally statement. In particular, note that the catch keyword is followed by an identifier in parentheses. This identifier is like a function argument. It names a local variable that exists only within the body of the catch block. JavaScript assigns whatever exception object or value was thrown to this variable:try {
// Normally, this code runs from the top of the block to the bottom
// without problems. But it can sometimes throw an exception,
// either directly, with a throw statement, or indirectly, by calling
// a method that throws an exception.
}
catch (e) {
// The statements in this block are executed if, and only if, the try
// block throws an exception. These statements can use the local variable
// e to refer to the Error object or other value that was thrown.
// This block may handle the exception somehow, may ignore the
// exception by doing nothing, or may rethrow the exception with throw.
}
finally {
// This block contains statements that are always executed, regardless of
// what happens in the try block. They are executed whether the try
// block terminates:
// 1) normally, after reaching the bottom of the block
// 2) because of a break, continue, or return statement
// 3) with an exception that is handled by a catch clause above
// 4) with an uncaught exception that is still propagating
}