\begin{quote}
Easily subclass and customize new Error types \end{quote}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8763}{}\doxysection{Examples}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8763}
To include in your project\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var errorEx = require('error-\/ex'); }

\end{DoxyCode}


To create an error message type with a specific name (note, that {\ttfamily Error\+Fn.\+name} will not reflect this)\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var JSONError = errorEx('JSONError');}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new JSONError('error');}
\DoxyCodeLine{err.name; //-\/> JSONError}
\DoxyCodeLine{throw err; //-\/> JSONError: error }

\end{DoxyCode}


To add a stack line\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var JSONError = errorEx('JSONError', \{fileName: errorEx.line('in \%s')\});}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new JSONError('error')}
\DoxyCodeLine{err.fileName = '/a/b/c/foo.json';}
\DoxyCodeLine{throw err; //-\/> (line 2)-\/> in /a/b/c/foo.json }

\end{DoxyCode}


To append to the error message\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var JSONError = errorEx('JSONError', \{fileName: errorEx.append('in \%s')\});}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new JSONError('error');}
\DoxyCodeLine{err.fileName = '/a/b/c/foo.json';}
\DoxyCodeLine{throw err; //-\/> JSONError: error in /a/b/c/foo.json }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8764}{}\doxysection{API}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8764}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8765}{}\doxysubsubsection{$<$tt$>$error\+Ex(\mbox{[}name\mbox{]}, \mbox{[}properties\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8765}
Creates a new Error\+Ex error type


\begin{DoxyItemize}
\item {\ttfamily name}\+: the name of the new type (appears in the error message upon throw; defaults to {\ttfamily Error.\+name})
\item {\ttfamily properties}\+: if supplied, used as a key/value dictionary of properties to use when building up the stack message. Keys are property names that are looked up on the error message, and then passed to function values.
\begin{DoxyItemize}
\item {\ttfamily line}\+: if specified and is a function, return value is added as a stack entry (error-\/ex will indent for you). Passed the property value given the key.
\end{DoxyItemize}
\end{DoxyItemize}

{\ttfamily stack}\+: if specified and is a function, passed the value of the property using the key, and the raw stack lines as a second argument. Takes no return value (but the stack can be modified directly).
\begin{DoxyItemize}
\item {\ttfamily message}\+: if specified and is a function, return value is used as new {\ttfamily .message} value upon get. Passed the property value of the property named by key, and the existing message is passed as the second argument as an array of lines (suitable for multi-\/line messages).
\end{DoxyItemize}

Returns a constructor (Function) that can be used just like the regular Error constructor.


\begin{DoxyCode}{0}
\DoxyCodeLine{var errorEx = require('error-\/ex');}
\DoxyCodeLine{}
\DoxyCodeLine{var BasicError = errorEx();}
\DoxyCodeLine{}
\DoxyCodeLine{var NamedError = errorEx('NamedError');}
\DoxyCodeLine{}
\DoxyCodeLine{// -\/-\/}
\DoxyCodeLine{}
\DoxyCodeLine{var AdvancedError = errorEx('AdvancedError', \{}
\DoxyCodeLine{    foo: \{}
\DoxyCodeLine{        line: function (value, stack) \{}
\DoxyCodeLine{            if (value) \{}
\DoxyCodeLine{                return 'bar ' + value;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{            return null;}
\DoxyCodeLine{        \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new AdvancedError('hello, world');}
\DoxyCodeLine{err.foo = 'baz';}
\DoxyCodeLine{throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{/*}
\DoxyCodeLine{    AdvancedError: hello, world}
\DoxyCodeLine{        bar baz}
\DoxyCodeLine{        at tryReadme() (readme.js:20:1)}
\DoxyCodeLine{*/ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8766}{}\doxysubsubsection{$<$tt$>$error\+Ex.\+line(str)$<$/tt$>$}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8766}
Creates a stack line using a delimiter

\begin{quote}
This is a helper function. It is to be used in lieu of writing a value object for {\ttfamily properties} values. \end{quote}

\begin{DoxyItemize}
\item {\ttfamily str}\+: The string to create
\begin{DoxyItemize}
\item Use the delimiter {\ttfamily s} to specify where in the string the value should go
\end{DoxyItemize}
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{var errorEx = require('error-\/ex');}
\DoxyCodeLine{}
\DoxyCodeLine{var FileError = errorEx('FileError', \{fileName: errorEx.line('in \%s')\});}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new FileError('problem reading file');}
\DoxyCodeLine{err.fileName = '/a/b/c/d/foo.js';}
\DoxyCodeLine{throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{/*}
\DoxyCodeLine{    FileError: problem reading file}
\DoxyCodeLine{        in /a/b/c/d/foo.js}
\DoxyCodeLine{        at tryReadme() (readme.js:7:1)}
\DoxyCodeLine{*/ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8767}{}\doxysubsubsection{$<$tt$>$error\+Ex.\+append(str)$<$/tt$>$}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8767}
Appends to the {\ttfamily error.\+message} string

\begin{quote}
This is a helper function. It is to be used in lieu of writing a value object for {\ttfamily properties} values. \end{quote}

\begin{DoxyItemize}
\item {\ttfamily str}\+: The string to append
\begin{DoxyItemize}
\item Use the delimiter {\ttfamily s} to specify where in the string the value should go
\end{DoxyItemize}
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{var errorEx = require('error-\/ex');}
\DoxyCodeLine{}
\DoxyCodeLine{var SyntaxError = errorEx('SyntaxError', \{fileName: errorEx.append('in \%s')\});}
\DoxyCodeLine{}
\DoxyCodeLine{var err = new SyntaxError('improper indentation');}
\DoxyCodeLine{err.fileName = '/a/b/c/d/foo.js';}
\DoxyCodeLine{throw err;}
\DoxyCodeLine{}
\DoxyCodeLine{/*}
\DoxyCodeLine{    SyntaxError: improper indentation in /a/b/c/d/foo.js}
\DoxyCodeLine{        at tryReadme() (readme.js:7:1)}
\DoxyCodeLine{*/ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_error_ex_README_autotoc_md8768}{}\doxysection{License}\label{md_sfcode_node_modules_error_ex_README_autotoc_md8768}
Licensed under the \href{http://opensource.org/licenses/MIT}{\texttt{ MIT License}}. You can find a copy of it in \mbox{[}LICENSE\mbox{]}(LICENSE). 