lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petrus Hyvönen <>
Subject Error when java exception
Date Mon, 04 Feb 2013 15:51:00 GMT

I have some strange error when an java exception occurs in the wrapped
library 'orekit', the exception text is not printed and a python error
"NameError: global name 'StringWriter' is not defined" occurs in

I am using the --use_full_names option, latest JCC from SVN.

It is in the file, mine looks like:

import os, sys

if sys.platform == 'win32':
  import jcc, _orekit
  import _orekit

__dir__ = os.path.abspath(os.path.dirname(__file__))

class JavaError(Exception):
  def getJavaException(self):
    return self.args[0]
  def __str__(self):
    writer = StringWriter()
    return "\n".join((super(JavaError, self).__str__(), "    Java
stacktrace:", str(writer)))

class InvalidArgsError(Exception):

_orekit._set_exception_types(JavaError, InvalidArgsError)

VERSION = "6.0.0"
CLASSPATH = [os.path.join(__dir__, "orekit-6.0-SNAPSHOT.jar"),
os.path.join(__dir__, "commons-math3-3.1.1.jar")]
CLASSPATH = os.pathsep.join(CLASSPATH)
_orekit._set_function_self(_orekit.initVM, _orekit)

from _orekit import *

With the error:

in __str__(self)
     13     return self.args[0]
     14   def __str__(self):
---> 15     writer = StringWriter()
     16     self.getJavaException().printStackTrace(PrintWriter(writer))
     17     return "\n".join((super(JavaError, self).__str__(), "    Java
stacktrace:", str(writer)))

NameError: global name 'StringWriter' is not defined

If I manually add an from import StringWriter, PrintWriter in the
__str__ function it seems to work (not if on module level, no idea why).
Could it be that the last line in, from orekit import * is
related to the non-full-names option?

my build string, if interesting is as follows:
python -m jcc  --use_full_names --shared --python orekit --version 6.0.0
--jar orekit-6.0-SNAPSHOT.jar --jar commons-math3-3.1.1.jar --package
java.util  java.util.Arrays  java.util.List  java.util.ArrayList
 java.util.Collection  java.util.Collections java.util.Set java.util.Map
java.util.HashMap java.util.Date --package --package java.lang
java.lang.System --package
org.apache.commons.math3.geometry.euclidean.threed.Vector3D --reserved
INFINITE --reserved ERROR --reserved OVERFLOW --reserved NO_DATA --reserved
min --reserved max --reserved mean --build --wininst

Any comments appriciated

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message