Hi,

I am working with build 0.9.4. I was trying to write an XPCOM component 
that would follow XPCOM exception protocol so that I can return my own 
exception that would be visible from JavaScript. I've been somewhat 
successful, in that JavaScript instead of its default message that it 
prints on a failure nsresult, printed this to console:

JavaScript error: 
 line 0: uncaught exception: null

but I do want the context information (e.g. line number), and I do want my 
exception string representation printed! JS knows it, and it should print 
it. And I hope I should not be writing JS-specific code in my component 
to achieve that, e.g. querying JS for current line number and stack frame. 

I debugged it to the point where I see that XPConnect actually gets my 
exception object, knows it's an nsIException, and verifies that the 
nsresult's returned by my method and by my exception's GetResult method are 
the same (NS_ERROR_FAILURE). From then on, I get lost in the tearoffs and 
wrappers and helpers and mentions of nsIClassInfo.

I declared my interface extending nsIException, and my class implements 
nsIException, mentions it in NS_IMPL_ISUPPORTS*, and defines all of its 
methods. The method GetMessage returns a copy of a static string, using 
nsMemory::Clone, and the same code is known to work with JavaScript in a 
non-exception class. The method ToString defers to GetMessage. The methods 
that return file name and various other location information all return 
nulls and zeros. To set the exception, I obtain the exception service 
through the service manager, then call 
nsIExceptionService::GetCurrentExceptionManager, then 
nsIExceptionManager::SetCurrentException.

What am I missing? Should I use NS_IMPL_ISUPPORTS*_CI so that the exception 
has classinfo? I am not using it for non-exception classes and they are 
visible from JS, so why should I here if JS knows itself to QI for 
nsIException. And how do I get JS to report context information for me? I 
can try various things, but I would prefer to know what I'm doing and why 
I'm doing it.

I looked for information on the web site, but found very little. In fact, 
the document about BlackConnect 
(http://www.mozilla.org/projects/blackwood/connect/RequirementsSpec.html) 
seems to be oblivious to the fact that there is an exception protocol in 
XPCOM:

 "Exceptions 
 XPCOM does not have exception model. It has error codes. BlackConnect
 should throw exceptions according to error codes and return error codes
 according to exceptions.
 Postponed for next version of BlackConnect"

Any help would be greatly appreciated. I suppose an answer could be added 
to the documentation and benefit other Mozilla projects like BlackConnect.

Thanks in advance.

--Michael
To reply via email remove -no and spam- from the address.

Reply via email to