From 4198198e0297cf0a26d2639b7a841abdae4954b2 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Thu, 23 Oct 2025 11:37:12 -0500 Subject: [PATCH] logger handles exception --- src/fancymath/__main__.py | 5 ++++- src/fancymath/vector.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fancymath/__main__.py b/src/fancymath/__main__.py index e4b9652..7f3777f 100644 --- a/src/fancymath/__main__.py +++ b/src/fancymath/__main__.py @@ -33,4 +33,7 @@ logger.info(f"{v1=}") logger.info(f"{v2=}") logger.info(f"{v3=}") -v4 = v2.dot([1,2,3]) \ No newline at end of file +try: + v4 = v2.dot([1,2,3]) +except ValueError as err: + logger.exception(err) diff --git a/src/fancymath/vector.py b/src/fancymath/vector.py index 48c549b..359717d 100644 --- a/src/fancymath/vector.py +++ b/src/fancymath/vector.py @@ -16,8 +16,8 @@ class Vector(object): def dot(self, v): """Returns the dot product with Vector *v*.""" if not isinstance(v, self.__class__): - logger.error(f"Expected an instance of {self.__class__}, but got {type(v)} instead.") - return None + msg = f"Expected an instance of {self.__class__}, but got {type(v)} instead." + raise ValueError(msg) d = self.x * v.x + self.y * v.y + self.z * v.z return d