如何检索发生错误的行号?
在下一个脚本中,该行输出(作为最后一次raise的结果)但没有行 num。在 JSError 对象中。
from spidermonkey import Runtime, JSError
runtime = Runtime()
context = runtime.new_context()
try:
context.execute( "function test(){ return 'OK' }; \n\ntest2()" )
except JSError as e:
print "ERROR!"
print "args = {0}".format( e.args )
print "message = {0}".format( e.message )
print "__dict__ = {0}".format( e.__dict__ )
raise
结果:
ERROR!
args = ('ReferenceError: test2 is not defined',)
message = ReferenceError: test2 is not defined
__dict__ = {}
Traceback (most recent call last):
File "test.py", line 7, in <module>
context.execute( "function test(){ return 'OK' }; \n\ntest2()" )
File "<anonymous JavaScript>", line 3, in JavaScript code
spidermonkey.JSError: ReferenceError: test2 is not defined