def test_exception(self): self.assertRaisesRegexp(SystemError, "This is a test exception message for JyNI.", DemoExtension.exceptionTest) try: DemoExtension.exceptionTest() self.assertEqual(1, 2) #would always fail, but is not reached if everything works as expected except SystemError: exc = sys.exc_info() self.assertEqual(exc[0], SystemError) self.assertEqual(str(exc[1]), "This is a test exception message for JyNI.")
def test_exception(self): self.assertRaisesRegexp(SystemError, "This is a test exception message for JyNI.", DemoExtension.exceptionTest) try: DemoExtension.exceptionTest() self.assertEqual( 1, 2 ) #would always fail, but is not reached if everything works as expected except SystemError: exc = sys.exc_info() self.assertEqual(exc[0], SystemError) self.assertEqual(str(exc[1]), "This is a test exception message for JyNI.")
#built with an IDE in debug mode: sys.path.append('../../DemoExtension/Debug') #in case you run it from src dir sys.path.append('./DemoExtension/Debug') #in case you run it from base dir #built with an IDE in release mode: sys.path.append( '../../DemoExtension/Release') #in case you run it from src dir sys.path.append('./DemoExtension/Release') #in case you run it from base dir #built with setup.py: sys.path.append('../../DemoExtension/build/lib.' + buildf + '-2.7') #in case you run it from src dir sys.path.append('./DemoExtension/build/lib.' + buildf + '-2.7') #in case you run it from base dir import DemoExtension #import java.lang.System as jsys #jsys.out.println("Jython is running!") #print "-------------------" print "sys.exc_info, initial: " + str(sys.exc_info()) try: print "We call a native method that creates an exception. However, this time we handle it..." DemoExtension.exceptionTest() except SystemError: print "...and entered except-area!" print "sys.exc_info: " + str(sys.exc_info()) print "Now lets look, what happens, if the exception is uncaught:" DemoExtension.exceptionTest() print "------------------- this line should never be printed"
#build with an IDE in debug mode: sys.path.append('../../DemoExtension/Debug') #in case you run it from src dir sys.path.append('./DemoExtension/Debug') #in case you run it from base dir #build with an IDE in release mode: sys.path.append('../../DemoExtension/Release') #in case you run it from src dir sys.path.append('./DemoExtension/Release') #in case you run it from base dir #build with setup.py on 64 bit machine: sys.path.append('../../DemoExtension/build/lib.linux-x86_64-2.7') #in case you run it from src dir sys.path.append('./DemoExtension/build/lib.linux-x86_64-2.7') #in case you run it from base dir #build with setup.py on 32 bit machine: sys.path.append('../../DemoExtension/build/lib.linux-i686-2.7') #in case you run it from src dir sys.path.append('./DemoExtension/build/lib.linux-i686-2.7') #in case you run it from base dir import DemoExtension #import java.lang.System as jsys #jsys.out.println("Jython is running!") #print "-------------------" print "sys.exc_info, initial: "+str(sys.exc_info()) try: print "We call a native method that creates an exception. However, this time we handle it..." DemoExtension.exceptionTest() except SystemError: print "...and entered except-area!" print "sys.exc_info: "+str(sys.exc_info()) print "Now lets look, what happens, if the exception is uncaught:" DemoExtension.exceptionTest() print "------------------- this line should never be printed"