Skip to content

Commit

Permalink
calc: gracefully handle ExpressionEvaluator.Error
Browse files Browse the repository at this point in the history
We might consider making this exception a standalone class, for less
wacky-looking error handling in this and other consumers of the
`tools.calculation` submodule. Doing `except a_function.Subclass` feels
weird and wrong.
  • Loading branch information
dgw committed Sep 21, 2023
1 parent 274470e commit a12e799
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sopel/modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def c(bot, trigger):
try:
result = eval_equation(eqn)
result = "{:.10g}".format(result)
except eval_equation.Error as err:
bot.reply("Can't process expression: {}".format(str(err)))
return
except ZeroDivisionError:
bot.reply('Division by zero is not supported in this universe.')
return
Expand Down

0 comments on commit a12e799

Please sign in to comment.