logger handles exception

This commit is contained in:
2025-10-23 11:37:12 -05:00
parent bac8d74803
commit 4198198e02
2 changed files with 6 additions and 3 deletions

View File

@@ -33,4 +33,7 @@ logger.info(f"{v1=}")
logger.info(f"{v2=}") logger.info(f"{v2=}")
logger.info(f"{v3=}") logger.info(f"{v3=}")
try:
v4 = v2.dot([1,2,3]) v4 = v2.dot([1,2,3])
except ValueError as err:
logger.exception(err)

View File

@@ -16,8 +16,8 @@ class Vector(object):
def dot(self, v): def dot(self, v):
"""Returns the dot product with Vector *v*.""" """Returns the dot product with Vector *v*."""
if not isinstance(v, self.__class__): if not isinstance(v, self.__class__):
logger.error(f"Expected an instance of {self.__class__}, but got {type(v)} instead.") msg = f"Expected an instance of {self.__class__}, but got {type(v)} instead."
return None raise ValueError(msg)
d = self.x * v.x + self.y * v.y + self.z * v.z d = self.x * v.x + self.y * v.y + self.z * v.z
return d return d