Michael Klepikov wrote:

> 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. 


This is all being worked on in bug 65080.

The "problem" is that the exception message is actually printed as the 
JavaScript engine *exits*, rather than as the exception is first 
detected, to allow exception handling by the engine.

> 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? 


Nothing.  It just doesn't work yet :(  What your code does is correct, 
and hopefully soon javascript will print your exception representation. 
  The bug is assigned to me, and I hope to get to it in a few weeks...

Mark.


Reply via email to