Errors generated by io.js fall into two categories: JavaScript errors and system
errors. All errors inherit from or are instances of JavaScript's [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
class and are guaranteed to provide *at least* the attributes available on that
class.
When an operation is not permitted due to language-syntax or
language-runtime-level reasons, a **JavaScript error** is generated and thrown
as an **exception**. If an operation is not allowed due to system-level
restrictions, a **system error** is generated. Client code is then given the
opportunity to **intercept** this error based on how the API **propagates** it.
The style of API called determines how generated errors are handed back, or
**propagated**, to client code, which in turn informs how the client may **intercept**
the error. Exceptions can be intercepted using the `try / catch` construct;
other propagation strategies are covered [below](#errors_error_propagation_and_interception).
## JavaScript Errors
<!--type=misc-->
JavaScript errors typically denote that an API is being used incorrectly, or that
there is a problem with the program as written.
### Class: Error
<!--type=class-->
A general error object. Unlike other error objects, `Error` instances do not
denote any specific circumstance of why the error occurred. Errors capture a
"stack trace" detailing the point in the program at which they were
instantiated, and may provide a description of the error.
**Note**: io.js will generate this class of error to encapsulate system
errors as well as plain JavaScript errors.
#### new Error(message)
Instantiates a new Error object and sets its `.message` property to the provided
message. Its `.stack` will represent the point in the program at which `new Error`
was called. Stack traces are subject to [V8's stack trace API](https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi).
Stack traces only extend to the beginning of synchronous code execution, *or* a number of frames given by
`Error.stackTraceLimit`, whichever is smaller.
#### error.message
A string of the value passed to `Error()` upon instantiation. The message will
also appear in the first line of the stack trace of the error. Changing this
property *may not* change the first line of the stack trace.
#### error.stack
A property that, when **accessed**, returns a string representing the point in the program
at which this error was instantiated. An example stacktrace follows:
Error: Things keep happening!
at /home/gbusey/file.js:525:2
at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)
at Actor.<anonymous> (/home/gbusey/actors.js:400:8)
at increaseSynergy (/home/gbusey/actors.js:701:6)
The first line is formatted as `<error class name>: <error message>`, and it is followed
by a series of stack frames (each line beginning with "at "). Each frame describes
a call site in the program that lead to the error being generated. V8 attempts to
display a name for each function (by variable name, function name, or object
method name), but occasionally it will not be able to find a suitable name. If
V8 cannot determine a name for the function, only location information will be
displayed for that frame. Otherwise, the determined function name will be displayed
with location information appended in parentheses.
Frames are **only** generated for JavaScript functions. If, for example, execution
synchronously passes through a C++ addon function called `cheetahify`, which itself
calls a JavaScript function, the frame representing the `cheetahify` call will **not**
be present in stacktraces:
```javascript
var cheetahify = require('./native-binding.node');
function makeFaster() {
// cheetahify *synchronously* calls speedy.
cheetahify(function speedy() {
throw new Error('oh no!');
});
}
makeFaster(); // will throw:
// /home/gbusey/file.js:6
// throw new Error('oh no!');
// ^
// Error: oh no!
// at speedy (/home/gbusey/file.js:6:11)
// at makeFaster (/home/gbusey/file.js:5:3)
// at Object.<anonymous> (/home/gbusey/file.js:10:1)
// at Module._compile (module.js:456:26)
// at Object.Module._extensions..js (module.js:474:10)
// at Module.load (module.js:356:32)
// at Function.Module._load (module.js:312:12)
// at Function.Module.runMain (module.js:497:10)
// at startup (node.js:119:16)
// at node.js:906:3
```
The location information will be one of:
*`native`, if the frame represents a call internal to V8 (as in `[].forEach`).
*`plain-filename.js:line:column`, if the frame represents a call internal to io.js.
*`/absolute/path/to/file.js:line:column`, if the frame represents a call in a user program, or its dependencies.
It is important to note that the string representing the stacktrace is only
generated on **access**: it is lazily generated.
The number of frames captured by the stack trace is bounded by the smaller of
`Error.stackTraceLimit` or the number of available frames on the current event
loop tick.
System-level errors are generated as augmented Error instances, which are detailed