From 99e0b96dd78aa8c2d006a356119ab17547aacd74 Mon Sep 17 00:00:00 2001 From: Gram Date: Mon, 20 Apr 2020 15:20:16 +0200 Subject: [PATCH] upd recipes --- docs/recipes.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/recipes.md b/docs/recipes.md index 9471d3d8..b9fc1634 100644 --- a/docs/recipes.md +++ b/docs/recipes.md @@ -50,7 +50,14 @@ If a contract needs only function arguments, use `pre`. If a contract checks onl ## Prefer `reason` over `raises` -Always try your best to tell why exception can be raised. +Always try your best to tell why exception can be raised. However, keep in mind that all exceptions from `reason` still have to be explicitly specified in `raises` since contracts are isolated and have no way to exchange information between each other: + +```python +@deal.reason(ZeroDivisionError, lambda a, b: b == 0) +@deal.raises(ZeroDivisionError) +def divide(a, b): + return a / b +``` ## Keep module initialization pure