Changeset 3052


Ignore:
Timestamp:
Sep 29, 2010 10:09:07 AM (11 years ago)
Author:
jwatson
Message:

Adding improved error diagnostics in the case where a non-hashable key is supplied as an index to a variable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/var.py

    r2999 r3052  
    294294        try:
    295295            return self._varval[ndx]
    296         except KeyError:
    297             msg = "Unknown index '%s' in variable %s\n" % (str(ndx), self.name)
     296        except KeyError: # thrown if the supplied index is hashable, but not defined.
     297            msg = "Unknown index '%s' in variable %s;" % (str(ndx), self.name)
    298298            if (isinstance(ndx, (tuple, list)) and len(ndx) != self.dim()) or \
    299299                   (ndx != self.dim()):
     
    303303                msg += "    Is the ordering of the indices correct?"
    304304            raise KeyError, msg
     305        except TypeError, msg: # thrown if the supplied index is not hashable
     306            msg2 = "Unable to index variable %s using supplied index with " % self.name
     307            msg2 += str(msg)
     308            raise TypeError, msg2
     309     
    305310
    306311    # TODO: Convert to 'has_XXX'
Note: See TracChangeset for help on using the changeset viewer.