0

エラーが発生した行番号を取得するには?

次のスクリプトでは、(最後の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
4

2 に答える 2