Month: November 2013
NBFFI version of the OpenDBXDriver
Hi!
We have built a NBFFI version of the OpenDBXDriver. The main idea of this is to provide a backward compatibility layer to people that use OpenDBX, while letting us move forward dropping the old FFI implementation. SLIDES
The configuration still supports to load the former version of the driver (no NBFFI)
Gofer it smalltalkhubUser: 'DBXTalk' project: 'Configurations'; configurationOf: 'OpenDBXDriver'; load. (((Smalltalk at: #ConfigurationOfOpenDBXDriver) perform: #project) perform: #version: with: ‘1.3’) load: 'FFIDriver'.
And the configuration with only NBFFI version.
Gofer it smalltalkhubUser: 'DBXTalk' project: 'Configurations'; configurationOf: 'OpenDBXDriver'; load. (((Smalltalk at: #ConfigurationOfOpenDBXDriver) perform: #project) perform: #version: with: ‘1.3’) load: 'NBFFIDriver'.
To use, writte in the Workspace and DoIt:
“to set the NBFFI bind” LibOpenDBXMap initialize. OpenDBX current: NBPharoOpenDBX new. “or to set the oldFFI bind” OpenDBX current: FFIOpenDBX ffiImplementationForOS .
Bye! 😀
Exceptions in Python
This post is dedicated to python, especially the handling of exceptions in the language, I take for granted that you already understand the concept, and I only concentrate on the syntax and variations that will allow the language. I will show how to create, throw, catch and test exceptions in python
Create Exceptions
class MiException(Exception): def__init__(self, value): self.value = value def__str__(self): return repr(self.value)
Throw Exceptions
if(some validation): #OK! else: raise Exception
Catch Exceptions:
try: #/*code that can throw exception*/ except: #/*do something if the exception is launched*/
Catch Exceptions:Discriminate by type of exception
try: #/*code that can throw exception*/ except NameError: print "The variable doesn't exist" except ValueError: print "The value is not a number"
Catch Exceptions:Capture several exceptions in the same except
try: #code that can throw exception except (NameError, ValueError): print "error"
Catch Exceptions:Do something if the exception is not thrown
try: #code that can throw exception except: print "error" else: print "It is OK"
Catch Exceptions:With finally/p>
try: z = x / y except ZeroDivisionError: print "Division for Zero" finally: print "Clean..."
Test Exceptions
Test: methods without parameters
def test_afunction_throws_exception(self): self.assertRaises(ExpectedException, afunction)
Test: methods with parameters
def test_afunction_throws_exception(self): self.assertRaises(ExpectedException, afunction, arg1, arg2)
Bye! 🙂