The code also forsees a possible error by verifying that the document really has a layer by that name, by investigating the hasByName property.