s/throw BadMojo/throw new BadMojo/g so we can test with instanceof later
add formatException() function
redo BadMojo() to construct a new object, we'll need the prototype chain set up right so we can test exceptions with instanceof
This commit is contained in:
rginda%netscape.com 2001-06-28 08:08:08 +00:00
Родитель aa829f037a
Коммит 65d0cc4783
1 изменённых файлов: 32 добавлений и 30 удалений

Просмотреть файл

@ -118,11 +118,11 @@ function dispatchCommand (text)
function display(message, msgtype) function display(message, msgtype)
{ {
if (typeof message == "undefined") if (typeof message == "undefined")
throw BadMojo(ERR_REQUIRED_PARAM, "message"); throw new BadMojo(ERR_REQUIRED_PARAM, "message");
if (typeof message != "string" && if (typeof message != "string" &&
!(message instanceof Components.interfaces.nsIDOMHTMLElement)) !(message instanceof Components.interfaces.nsIDOMHTMLElement))
throw BadMojo(ERR_INVALID_PARAM, ["message", String(message)]); throw new BadMojo(ERR_INVALID_PARAM, ["message", String(message)]);
if (typeof msgtype == "undefined") if (typeof msgtype == "undefined")
msgtype = MT_INFO; msgtype = MT_INFO;
@ -248,28 +248,26 @@ function fillInTooltip(tipElement)
return retVal; return retVal;
} }
function formatEvalException (ex, prefix) function formatException (ex)
{ {
var str = ""; if (ex instanceof BadMojo)
return getMsg (MSN_FMT_BADMOJO,
if (ex.fileName && ex.lineNumber && ex.message) [ex.errno, ex.message, ex.fileName, ex.lineNumber,
{ ex.functionName]);
if (!ex.name)
ex.name = "Error";
/* if it looks like a normal exception, print all the bits */
str = getMsg (MSN_EVAL_ERROR, [ex.name, ex.fileName, ex.lineNumber]);
if (ex.functionName)
str += " (" + ex.functionName + ")";
str += ": " + ex.message;
}
else
/* otherwise, just convert to a string */
str = getMsg (MSN_EVAL_THREW, String(ex));
return str;
if (ex instanceof Error)
return getMsg (MSN_FMT_JSEXCEPTION, [ex.name, ex.message, ex.fileName,
ex.lineNumber]);
return String(ex);
}
function formatEvalException (ex)
{
if (ex instanceof BadMojo || ex instanceof Error)
return formatException (ex);
return getMsg (MSN_EVAL_THREW, String(ex));
} }
function htmlVA (attribs, href, contents) function htmlVA (attribs, href, contents)
@ -418,19 +416,23 @@ const ERR_NO_DEBUGGER = 4;
const ERR_FAILURE = 5; const ERR_FAILURE = 5;
const ERR_NO_STACK = 6; const ERR_NO_STACK = 6;
/* venkman exception factory, can be used with or without |new|. /* venkman exception class */
* throw BadMojo (ERR_REQUIRED_PARAM, MSG_VAL_OBJECT);
* throw new BadMojo (ERR_NOT_IMPLEMENTED);
*/
function BadMojo (errno, params) function BadMojo (errno, params)
{ {
var msg = getMsg(exceptionMsgNames[errno], params); var msg = getMsg(exceptionMsgNames[errno], params);
dd ("new BadMojo (" + errno + ": " + msg + ") from\n" + getStackTrace()); dd ("new BadMojo (" + errno + ": " + msg + ") from\n" + getStackTrace());
return {message: msg, name: "Error " + errno, this.message= msg;
fileName: Components.stack.caller.filename, this.errno = errno;
lineNumber: Components.stack.caller.lineNumber, this.fileName = Components.stack.caller.filename;
functionName: Components.stack.caller.functionName}; this.lineNumber = Components.stack.caller.lineNumber;
this.functionName = Components.stack.caller.name;
}
BadMojo.prototype.toString =
function bm_tostring ()
{
return formatException (this);
} }
/* console object */ /* console object */