added error checking via python internal casting routine and exception handling