JavaScript Bible, Gold Edition part 122

JavaScript Bible, Gold Edition part 122. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 1058 Part IV JavaScript Core Language Reference The single catch block in Listing 39-7 executes only if one of the statements in the try block throws an exception. The exceptions may be not only one of the four specific ones named in the catch block but also syntax or other errors that could occur inside the try block. That s why you have a last-ditch case to handle truly unexpected errors. Your job as scripter is to not only anticipate errors but also to provide clean ways for the exceptions to be handled whether they be through judiciously worded alert dialog boxes or perhaps even some self-repair. For example in the case of the invalid character error for createElement your script may attempt to salvage the data passed to the attachToEnd function and reinvoke the method passing theNode value as-is and the repaired value originally passed to newTag. If your repairs were successful the try block would execute without error and carry on with the user s being completely unaware that a nasty problem had been averted. A finally block contains code that always executes after a try block whether or not the try block succeeds without throwing an error. Unlike the catch block a finally block does not receive an error object as a parameter so it operates very much in the dark about what transpires inside the try block. If you include both catch and finally blocks after a try block the execution path depends on whether an exception is thrown. If no exception is thrown the finally block executes after the last statement of the try block runs. But if the try block throws an exception program execution runs first to the catch block. After all processing within the catch block finishes the finally block executes. In development environments that give programmers complete control over resources such as memory allocation a finally block may be used to delete some temporary items generated in the try block whether or not an exception occurs in the try block. Currently JavaScript .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.