Changeset 11

Show
Ignore:
Timestamp:
04/23/07 14:58:16 (2 years ago)
Author:
hines
Message:

a good deal more exception handling with messages, though by no means
complete.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/pygetsetcall/src/nrnpython/nrnpy_hoc.cpp

    r10 r11  
    156156                } 
    157157        } 
     158        if (!sym) { 
     159                char e[200]; 
     160                sprintf(e, "'%s' is not a hoc variable name.", name); 
     161                PyErr_SetString(PyExc_LookupError, e); 
     162        } 
    158163        return sym; 
    159164} 
     
    481486                                return 0; 
    482487                        }else{ 
     488                                char e[200]; 
     489                                sprintf(e, "'%s' requires subscript for assignment", n); 
     490                                PyErr_SetString(PyExc_TypeError, e); 
    483491                                return -1; 
    484492                        } 
     
    489497        switch (sym->type) { 
    490498        case VAR: // double* 
     499                if (ISARRAY(sym)) { 
     500                        PyErr_SetString(PyExc_TypeError, "wrong number of subscripts"); 
     501                        return -1; 
     502                } 
    491503                hoc_pushs(sym); 
    492504                hoc_evalpointer(); 
     
    519531                break; 
    520532        default: 
     533                PyErr_SetString(PyExc_TypeError, "not assignable"); 
     534                err = -1; 
    521535                break; 
    522536        } 
     
    541555        PyObject* result = NULL; 
    542556        PyHocObject* po = (PyHocObject*)self; 
    543         assert(po->sym_); 
     557        if (!po->sym_) { 
     558                PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); 
     559                return NULL; 
     560        } 
    544561        assert(po->type_ == 3); 
    545562        Arrayinfo* a = hocobj_aray(po->sym_, po->ho_); 
     
    576593        int err = -1; 
    577594        PyHocObject* po = (PyHocObject*)self; 
    578         assert(po->sym_); 
     595        if (!po->sym_) { 
     596                PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); 
     597                return -1; 
     598        } 
    579599        assert(po->type_ == 3); 
    580600        Arrayinfo* a = hocobj_aray(po->sym_, po->ho_); 
    581         assert(a->nsub - 1 ==  po->nindex_); 
     601        if (a->nsub - 1 !=  po->nindex_) { 
     602                PyErr_SetString(PyExc_TypeError, "wrong number of subscripts"); 
     603                return -1; 
     604        } 
    582605        if (po->ho_) { 
    583606                eval_component(po, i);