Can this code generate a KeyError? I am new to python, I just want to clarify, since a verified insert cannot throw a KeyError exception.
def add(self, name, company): try: self.identity[self.id] = { 'name': name, 'company': company } return self.identity except KeyError: raise NameNotAdded
Here, identity is a dictionary and id is an initialized int elsewhere and NameNotAdded is a custom exception.
KeyError, TypeError, , , . Python , a TypeError.
KeyError
TypeError
, dict, MemoryError - OverflowError, ( sys.maxsize). , .:)
dict
MemoryError
OverflowError
sys.maxsize
KeyError.
A KeyError , . .
Source: https://habr.com/ru/post/1610182/More articles:feature Union of heterogeneous signs - pythonSailsJS / MySQL: Unknown column "NaN" in the "list of fields" - node.jshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1610179/is-it-possible-to-prevent-suspend-in-lob-uwp-desktop-applicationbackground-task&usg=ALkJrhjQ5DF5vfQaiFCYOxBQRo7gEvWXYgHow can I create a Python package with a platform? - pythonSaving Mongoose with objectId - node.jsConfirm the uniqueness of the fields in the list - listFreezing all but one positional argument - pythonUnable to deploy my application in OpenShift: "Failed to: install control for / var / lib / openshift / XXX / jbossews" - mongodbHow to download css for Mediawiki tag extension? - cssCIColorClamp does not work correctly on OS X El Capitan - cocoaAll Articles