lucene-pylucene-dev mailing list archives

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

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

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

It is in the __init__.py file, mine looks like:

import os, sys

if sys.platform == 'win32':
  import jcc, _orekit
else:
  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()
    self.getJavaException().printStackTrace(PrintWriter(writer))
    return "\n".join((super(JavaError, self).__str__(), "    Java
stacktrace:", str(writer)))

class InvalidArgsError(Exception):
  pass

_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.CLASSPATH = CLASSPATH
_orekit._set_function_self(_orekit.initVM, _orekit)

from _orekit import *


With the error:

C:\Users\phy\Desktop\WinPy\WinPython-32bit-2.7.3.3\python-2.7.3\lib\site-packages\orekit\__init__.pyc
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 java.io 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 __init__.py, 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 java.io java.io.InputStream
java.io.StringWriter java.io.StringReader --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
Regards
/Petrus

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