You should probably read that entire document.
What may not be clear is that XPConnect does automatic conversions between exceptions and nsresults. So, if JS code throws an exception when called by C++ code then the C++ code will get an appropriate nsresult. And if you use 'new Components.Exception(...)' then you can control what nsresult code is passed through. Also, if JS code calls C++ and the C++ returns an error result then the JS code receives an exception. XPConnect also plays well with the ExceptionService system so both languages (and Python too!) can have access to the actual exception objects.
This was all discussed in detail on this newsgroup as it was being designed and implemented. It is unfortunate that we didn't write better documents. But, searching this newsgroup using Google Groups will uncover a lot of very useful information.
John.
Lev Serebryakov wrote:
I'm having in my IDL file:
=================================================== #include "nsISupports.idl" [scriptable, uuid(....)] interface nsIXXXException : nsISupports { readonly attribute wstring message; };
[scriptable, uuid(.....)] interface nsIXXX : nsISupports { void logIn() raises(nsIXXXException); }; ===================================================
I have nsIXXXException implemented in JavaScript, but it Factory is not registered (I don't want to allow create instances of this component outside my main component):
===================================================
function XXXException( message )
{
this._m = message;
return this;
}
XXXException.prototype = { _m: '', get message() { return this._m; },
QueryInterface: function (iid) { if( ! iid.equals( Components.interfaces.nsIXXXException ) && ! iid.equals( Components.interfaces.nsISupports ) ) throw Components.results.NS_ERROR_NO_INTERFACE; return this; } }; ===================================================
My main component (which is have registered ContractID, etc), create and throw exception:
===================================================
....
throw new XXXException( 'Bad thing failed' );
....
===================================================
And component's client catch `NS_ERROR_XPC_JS_THREW_JS_OBJECT' exception!
How could I convert JavaScript object into interface (like when I pass JS object to addEventListener() call) without calling Components.classes[CID].createInstance()?
Lev Serebryakov Programmer JetBrains, Inc http://www.jetbrains.com "Develop with pleasure!"
_______________________________________________ Mozilla-xpcom mailing list [email protected] http://mail.mozilla.org/listinfo/mozilla-xpcom
