5 /********************************* Copyright **********************************/
9 * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved.
10 * Copyright (c) Michael O'Brien, 1994-1995. All Rights Reserved.
12 * This software is distributed under commercial and open source licenses.
13 * You may use the GPL open source license described below or you may acquire
14 * a commercial license from Mbedthis Software. You agree to be fully bound
15 * by the terms of either license. Consult the LICENSE.TXT distributed with
16 * this software for full details.
18 * This software is open source; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2 of the License, or (at your
21 * option) any later version. See the GNU General Public License for more
22 * details at: http://www.mbedthis.com/downloads/gplLicense.html
24 * This program is distributed WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 * This GPL license does NOT permit incorporating this software into
28 * proprietary programs. If you are unable to comply with the GPL, you must
29 * acquire a commercial license to use this software. Commercial licenses
30 * for this software and support services are available from Mbedthis
31 * Software at http://www.mbedthis.com
35 /********************************** Includes **********************************/
41 /************************************ Code ************************************/
43 * Parse the args and return the message. Convert non-string args using
47 static char *getMessage(Ejs *ep, int argc, EjsVar **argv)
52 } else if (argc == 1) {
53 if (! ejsVarIsString(argv[0])) {
54 if (ejsRunMethod(ep, argv[0], "toString", 0) < 0) {
57 return ep->result->string;
60 return argv[0]->string;
64 /* Don't call ejsError here or it will go recursive. */
70 /******************************************************************************/
72 * Error Constructor and also used for constructor for sub classes.
74 * Usage: new Error([message])
77 int ejsErrorCons(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv)
81 msg = getMessage(ep, argc, argv);
86 ejsSetPropertyToString(ep, thisObj, "name", ejsGetBaseClassName(thisObj));
87 ejsSetPropertyToString(ep, thisObj, "message", msg);
89 ejsSetPropertyToUndefined(ep, thisObj, "stack");
91 stack = ejsFormatStack(ep);
93 ejsSetPropertyToString(ep, thisObj, "stack", stack);
97 if (ejsObjHasErrors(thisObj)) {
104 /******************************************************************************/
106 int ejsDefineErrorClasses(Ejs *ep)
108 if (ejsDefineClass(ep, "Error", "Object", ejsErrorCons) == 0 ||
109 ejsDefineClass(ep, "AssertError", "Error", ejsErrorCons) == 0 ||
110 ejsDefineClass(ep, "EvalError", "Error", ejsErrorCons) == 0 ||
111 ejsDefineClass(ep, "InternalError", "Error", ejsErrorCons) == 0 ||
112 ejsDefineClass(ep, "IOError", "Error", ejsErrorCons) == 0 ||
113 ejsDefineClass(ep, "MemoryError", "Error", ejsErrorCons) == 0 ||
114 ejsDefineClass(ep, "RangeError", "Error", ejsErrorCons) == 0 ||
115 ejsDefineClass(ep, "ReferenceError", "Error", ejsErrorCons) == 0 ||
116 ejsDefineClass(ep, "SyntaxError", "Error", ejsErrorCons) == 0 ||
117 ejsDefineClass(ep, "TypeError", "Error", ejsErrorCons) == 0) {
119 return MPR_ERR_CANT_INITIALIZE;
124 /******************************************************************************/
127 void ejsErrorDummy() {}
129 /******************************************************************************/
130 #endif /* BLD_FEATURE_EJS */
138 * vim600: sw=4 ts=4 fdm=marker