`

The try statement:

阅读更多
/*
官网原文:
In JScript, the variable used to hold a caught exception is visible in the enclosing scope. The variable exists after the catch clause has finished executing but ceases to exist after the function where the catch clause was located exits.
*/
function foo() 
{
    try 
    { 
       throw "hello"; 
    } 
    catch(x) 
    { 
         document.write(x); 
    }
      document.write(x); // x should not be visible here } foo();
/*
Output:
    IE: hellohello 
    FF: hello (followed by error „x is not defined‟) 
 Opera: same as FF 
Safari: same as FF
*/

/*
官网原文:
    Catch is defined as creating a new object with the caught object as a property and putting the new object at the head of the scope chain. If the caught object is a function, calling it within the catch supplies the head of the scope chain as the this value. The called function can add properties to this object. This implies that for code of this shape:
    The reference to 'x' within the catch is not necessarily to the local declaration of 'x'; this gives Catch the same performance problems as with. If the call to E above were specified to supply the global object (rather than the head of the scope chain) as the this value, the performance issue evaporates and the catch variable can be treated as a local scoped to the catch clause.
*/
function foo()
{ 
	this.x = 11; 
} 
x = "global.x";
try
{ 
	throw foo;
} 
catch(e)
{
	document.write(x) // Should print "global.x"
	e(); 
	document.write(x) // Should add x to e // (Both IE and Firefox modify the global x)
}
document.write(x);
/*
Output: 
     IE: prints "global.x1111 
     FF: same as IE 
  Opera: prints "global.x11global.x"
 Safari: same as Opera
*/
分享到:
评论

相关推荐

    微软内部资料-SQL性能优化3

    To determine the transaction isolation level currently set, use the DBCC USEROPTIONS statement, for example: USE pubs GO SET TRANSACTION ISOLATION LEVEL REPEATABLE READ GO DBCC USEROPTIONS GO ...

    powerbuilder CrazySQLSource 3.9.2源码

    The first column in the select statement will be used for filtering and inserting into the SQL editor window. Here’s an example of where you can use a custom list: 1. Enter a new item in the My...

    Addison.Wesley.C++.by.Dissection.2002.pdf

    - **The return Statement:** Explains the `return` statement. - **Function Prototypes:** Describes the purpose and use of function prototypes. - **Call-By-Value:** Explains the call-by-value mechanism....

    The Little Prover

    What does it mean for a statement to be true? Some statements can be verified directly. To determine whether a particular omelette is delicious, we merely have to taste the omelette. Our answer is ...

    数据库工具类DatabaseUtil.java

    * Create a updatable and scrollable statement from the database connection * and return it. * * @return Statement */ public Statement getUpdatableStatement() { try { Statement statement = get...

    google api php client

    The method used is a matter of preference, but *it will be very difficult to use this library without first understanding the JSON syntax for the API*, so it is recommended to look at the [APIs ...

    SQL Server 2014 Development Essentials - Masood-Al-Farooq, Basit A. [SRG].pdf

    delete the data using the DELETE statement, and how to update existing data using the UPDATE statement. This chapter also covers the SELECT…INTO, MERGE, and TRUNCATE TABLE statements, and it ...

    Python核心编程(第二版)第十章练习答案

    - (a) `try: statement_A except: else: statement_B` - (b) `try: statement_A statement_B except:` **答案**: - 情况1:如果 `statement_A` 执行出错,则 (a) 和 (b) 都不会执行 `statement_B`。 - 情况2:...

    关于Java中try finally return语句的执行顺序浅析

    System.out.println("the previous statement of try block"); i = i / 0; try { System.out.println("try block"); return i; } finally { System.out.println("finally block"); } } } 这个示例代码的...

    JSP Simple Examples

    We can declare multiple try blocks inside the try block. The most specific exception which can be thrown is written on the top in the catch block following by the less specific least. kilometers per...

    python3.6.5参考手册 chm

    PEP 343: The ‘with’ statement Writing Context Managers The contextlib module PEP 366: Explicit Relative Imports From a Main Module PEP 370: Per-user site-packages Directory PEP 371: The ...

    jdk1.7_80 window.64

    - **Try-with-resources statement:** Automatically closes resources like files or database connections after use, preventing resource leaks. 3. **API Updates:** - **NIO.2 (New I/O API):** ...

    java 连接数据库(MYSQL)的经典代码

    System.out.println("Error creating statement: " + e.getMessage()); e.printStackTrace(); } ``` 5. 执行SQL: 使用`Statement`对象执行SQL查询或更新操作。例如,查询数据库中的数据: ```java String ...

    the practice for java

    总结,"the practice for java"不仅涵盖了Java语言的基本概念,还深入到JDBC这一核心领域,旨在帮助开发者熟练掌握Java编程,并能够灵活运用JDBC进行数据库操作,提升开发效率和代码质量。在实践中不断学习和分享,...

    Servlet查询数据库案例--Query(java源码)

    // Now try to execute the query and display the results in a table Statement statement = null; // An object to execute the query try { // Create a statement to use statement = db....

    java7帮助文档

    The ability to use a try-with-resources statement to automatically close resources of type Connection, ResultSet, and Statement; see Closing Connections in Processing SQL Statements. RowSet 1.1: The ...

    Java数据库编程接口

    3. 创建Statement:通过`Connection.createStatement()`创建`Statement`对象,准备执行SQL语句。 4. 执行SQL:使用`Statement.execute()`系列方法执行SQL。 5. 处理结果:如果执行的是查询语句,通过`ResultSet`处理...

    大学英语(上)教程 电子书

    Instead of waiting for the teacher to explain, they try to find the patterns and the rules for themselves. They are good guessers who look for clues and form their own conclusions. When they guess ...

Global site tag (gtag.js) - Google Analytics