1. Trying to read a property from an undefined value, or using a function that does not exists, will cause an error to be signaled.
2. Checking input is always a judgment call—you have to identify the mistakes that are likely to occur and that are likely to have subtle, complicated effects (rather than just causing an error right away).
3. When a function encounters a problem that it cannot solve itself, one possible reaction is to return a value that it could not normally return. It does, however, have its downsides. First, what if the function can already return every possible kind of value? The second issue with returning special values is that it can sometimes lead to a whole lot of clutter. If a piece of code is called 10 times, you have to check 10 times whether the special value was returned.
4. It is possible for code to raise (or throw) an exception, which is a value. Raising an exception somewhat resembles a super-charged return from a function—it does not just jump out of the current function but also out of its callers, all the way up to the top-level call that started the current execution. This is called unwinding the stack. It is possible to set obstacles for exceptions along the stack. These catch the exception as it is zooming down and can do something with it, after which the program continues running at the point where the exception was caught.
5. throw is the keyword that is used to raise an exception. The keyword try sets up an obstacle for exceptions: When the code in the block after it raises an exception, the catch block will be executed. The variable named in parentheses after the word catch will hold the exception value when this block executes. try statements can also be followed by a finally keyword, which means “no matter what happens, run this code after trying to run the code in the try block.” If a function has to clean something up, the cleanup code should usually be put into a finally block.
6. A special type of objects is raised for problems like getting properties from undefined. These always have a message property containing a description of the problem. You can raise similar objects using the new keyword and the Error constructor, giving the message as argument: throw new Error("Wolf!");
相关推荐
An advanced guide to Enterprise Integration using Apache ...Chapter 4. Beans Chapter 5. Enterprise Integration Patterns Chapter 6. Components and Endpoints Chapter 7. Error Handling Chapter 8. Testing
Chapter 4. Beginning the QuickPoll Application Chapter 5. Error Handling Chapter 6. Documenting REST Services Chapter 7. Versioning, Paging, and Sorting Chapter 8. Security Chapter 9. Clients and ...
Chapter 4. A Guided Tour of Xcode 7 Chapter 5. An Introduction to Xcode 7 Playgrounds Chapter 6. Swift Data Types, Constants and Variables Chapter 7. Swift Operators and Expressions Chapter 8. Swift ...
Exceptions and Error Handling Chapter 12. Iterators and Generators Chapter 13. Functions, and the Power of Abstract Thinking Chapter 14. Asynchronous Programming Chapter 15. Date and Time Chapter 16....
Error Handling Chapter 2. RPG Character Set Chapter 3. Control Specifications Chapter 4. File Description Specifications Chapter 5. Extension Specifications Chapter 6. Line Counter Specifications ...
Error Handling Chapter 11. Namespaces, Scopes, and Modules Chapter 12. Input and Output Chapter 13. Testing Chapter 14. Comprehensive Examples Chapter 15. Symbolic Computations - SymPy
Chapter 4. Rendering the Response with XHTML and CSS XHTML CSS Part II: Creating and Using the JavaScript Engine Chapter 5. Object-Oriented JavaScript Object-Oriented Approaches Using the...
Chapter 4. Blocks, Conditional Statements, and Iterative Programming Section 4.1. Block Structure of Stored Programs Section 4.2. Conditional Control Section 4.3. Iterative Processing with ...
Chapter 4. Design and Testability Chapter 5. Testing Principles Part II: Testing and Testability Patterns Chapter 6. The Basics Chapter 7. String Handling Chapter 8. Encapsulation and Override ...
Chapter 4. Cross-Site Scripting Defense Chapter 5. Cross-Site Request Forgery Defense and Clickjacking Chapter 6. Protecting Sensitive Data Chapter 7. SQL Injection and Other Injection Attacks Chapter...
With Swift 2 comes even better performance, a new error handling API, protocol extensions, and super support for availability checking. This book will equip you with all the practical programming ...
Chapter 4. Management Mechanisms The Registry Services Windows Management Instrumentation Conclusion Chapter 5. Startup and Shutdown Boot Process Troubleshooting Boot and Startup ...
Design websites for mobile devices, localization, and error handling Provide security by implementing a membership system Inject script code into your site using JavaScript and jQuery Use Responsive ...
Error Handling Section 3.11. Summary Section 3.12. Further Information Chapter 4. The OpenGL Programmable Pipeline Section 4.1. The Vertex Processor Section 4.2. The Fragment Processor Section 4.3. ...
Chapter 4. Structuring Data And Matching Patterns Chapter 5. Higher Order Functions And Error-Handling Chapter 6. Using Traits And Oop In Rust Chapter 7. Ensuring Memory Safety And Pointers Chapter 8....
Chapter 4. Software Reliability and Quality Assurance 85 4.1 Verification and Validation 85 4.2 Software Quality Assurance 87 4.3 Software Quality 89 4.4 Capability Maturity Model (SEI-CMM...
1.2.1 Languages that influenced Go.........................................................................4 1.2.2 Why a new language?....................................................................
Chapter 4. Elementary TCP Sockets Section 4.1. Introduction Section 4.2. socket Function Section 4.3. connect Function Section 4.4. bind Function Section 4.5. listen Function Section 4.6....
Combinators, Conditionals, and Error Handling Chapter 6. Using Concurrency and Parallelism with Schedulers Chapter 7. Testing Your RxJava Application Chapter 8. Resource Management and Extending ...
1.2.1 Languages that influenced Go.........................................................................4 1.2.2 Why a new language?....................................................................