Closed
Bug 416108
Opened 17 years ago
Closed 16 years ago
Error console does not display custom thrown error from listener
Categories
(Core :: XPConnect, defect)
Core
XPConnect
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: com, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
The error console has unexpected behaviour when errors are thrown from a listener instead of a direct handler such as "onclick".
An example:
***********************************************************
function handler()
{
throw new Error("handler error");
}
<button onclick="handler()">Throw error from onclick</button>
<button id="btn1">Throw error from click handler</button>
<script type="text/javascript">
var element = document.getElementById("btn1");
element.addEventListener("click", handler, false);
</script>
***********************************************************
Clicking the first button will produce the following error in the error console:
"handler error"
Clicking the second button will produce the following error in the error console:
[Exception... "'Error: handler error' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
Now let's say I want to throw a custom error type from the handler.
Example:
***********************************************************
function MyError(msg)
{
this.message = msg;
this.toString = function toString()
{
return "MyError: (" + this.message + ")";
}
}
MyError.prototype = new Error();
function handler()
{
throw new MyError("handler error");
}
<button onclick="handler()">Throw error from onclick</button>
<button id="btn1">Throw error from click handler</button>
<script type="text/javascript">
var element = document.getElementById("btn1");
element.addEventListener("click", handler, false);
</script>
***********************************************************
In this case clicking the first button shows this error:
uncaught exception: MyError: (handler error)
Now the biggest problem is that clicking the second button will not show anything in the error console!
When removing the toString method from MyError I will see this message:
[Exception... "'Error: handler error' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
Custom exceptions and event handlers are important in my complex javascript architecture. Therefore I hope this can be fixed.
Reproducible: Always
Comment 1•17 years ago
|
||
See also https://bugzilla.mozilla.org/show_bug.cgi?id=418346
Robert its helpful if you attach a complete example file so others don't have to guess if they reproduced what you see.
I created my own files and confirm the overall problem. In firebug I can see that the throw executes in the second button case (the addEventListener case), but the throw does not propagate to the observer. Its probably caught by xpconnect.
One question is the role of the W3C definition of addEventListener and EventListener interface in the expected behavior. In any case an error message should be delivered to the developer here.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•17 years ago
|
Component: Error Console → XBL
Product: Firefox → Core
QA Contact: error.console → xbl
Comment 2•17 years ago
|
||
Uh... Gavin, what does this have to do with XBL?
Comment 3•17 years ago
|
||
And is this a problem on trunk? This bug could really use an actual HTML file attached to it that shows the problem... Copy/pasting from comments often changes the whitespace, which can cause the testcase to behave differently.
Note regarding the attachment example:
"click handler" uses the onclick attribute.
"click listener" uses addEventListener.
Comment 6•17 years ago
|
||
(In reply to comment #2)
> Uh... Gavin, what does this have to do with XBL?
Sorry, I meant xpconnect but somehow picked XBL.
Component: XBL → XPConnect
QA Contact: xbl → xpconnect
Comment 7•17 years ago
|
||
I can confirm this on trunk. Blake, want to take a look?
Flags: wanted1.9.0.x?
Version: unspecified → Trunk
Comment 8•17 years ago
|
||
Looks like to be a duplicate of bug 415498
Comment 9•17 years ago
|
||
(In reply to comment #8)
> Looks like to be a duplicate of bug 415498
Sorry this one seems different after all.
OS: Windows XP → All
Hardware: PC → All
Comment 10•16 years ago
|
||
ok almost all of the testcases here are invalid (sadly for a half dozen different reasons).
part one. failure to use the Error constructor:
there's a request /somewhere/ that the default error constructor default to assigning line numbers, however whether that happens is a spidermonkey thing and is among the out of scope bits.
The proper error constructor is this:
Error("message", "file", line=100)
js> throw Error("message", "file", line=100)
file:100: message
if you don't pass a line number or a file then please don't expect us to report them. user error. invalid.
part 2. event listeners lose track of line numbers
iirc this is the addEventListener cases.
now there is a question about boxing and promoting.
there's actually one bug somewhere in here, however your testcase while appreciated is so bad that I've filed my own bug.
Status: NEW → RESOLVED
Closed: 16 years ago
Flags: wanted1.9.0.x?
Resolution: --- → INVALID
Reporter | ||
Comment 11•16 years ago
|
||
(In reply to comment #10)
Nice to say that the testcases are wrong, but not say why.
Furthermore, you keep going on about reporting line numbers, while the main problem is that the errors are not shown at all! Is your response even about this bug?
Therefore, I fail to see how this bug has been resolved.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Comment 12•16 years ago
|
||
oh brother. upgrade to firefox 3.
i tried each of the attachment 305983 [details]'s links, they all report messages in the js console.
Status: REOPENED → RESOLVED
Closed: 16 years ago → 16 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•