{"id":27883,"library":"jinja-try-catch","title":"jinja-try-catch","description":"Jinja2 extension adding {% try %} {% catch %} exception handling blocks. Version 0.1.1, requires Python >=3.7. Low release cadence, maintained as needed.","status":"active","version":"0.1.1","language":"python","source_language":"en","source_url":"https://github.com/RewstApp/jinja-try-catch","tags":["jinja2","extension","exception-handling","template"],"install":[{"cmd":"pip install jinja-try-catch","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required; the extension works with Jinja2 templates.","package":"Jinja2","optional":false}],"imports":[{"note":"Wrong if trying to import from submodule; correct top-level import.","wrong":"from jinja_try_catch.try_catch import TryExtension","symbol":"TryExtension","correct":"from jinja_try_catch import TryExtension"}],"quickstart":{"code":"from jinja2 import Environment\nfrom jinja_try_catch import TryExtension\n\nenv = Environment(extensions=[TryExtension()])\ntemplate = env.from_string(\"\"\"\n{% try %}\n    {{ 1/0 }}\n{% catch %}\n    Caught error: {{ error }}\n{% endtry %}\n\"\"\")\nprint(template.render())\n# Output: Caught error: division by zero\n","lang":"python","description":"Instantiate Jinja2 Environment with TryExtension; use {% try %}...{% catch %}...{% endtry %} blocks. Within catch block, `error` variable holds the exception message."},"warnings":[{"fix":"Only access `{{ error }}` within the {% catch %} block.","message":"`error` variable is only available inside the {% catch %} block. Referencing it outside will cause an undefined variable error.","severity":"gotcha","affected_versions":"all"},{"fix":"Continue using `TryExtension` class; no current deprecation but be aware of potential API changes.","message":"Extension registered via class name. Future versions may change the API for enabling extensions; check changelog.","severity":"deprecated","affected_versions":"0.1.x"},{"fix":"Use conditional logic inside catch block if needed: `{% catch %}{% if 'specific' in error %}...{% endif %}{% endtry %}`.","message":"Catch block catches all exceptions; no filtering by exception type is supported.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Add `TryExtension` to `extensions` list when creating Environment: `Environment(extensions=[TryExtension()])`","cause":"Extension not loaded/enabled in the Jinja2 environment.","error":"jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'try'."},{"fix":"Only use `{{ error }}` within the {% catch %} block.","cause":"Using `{{ error }}` outside the {% catch %} block or before a try block.","error":"NameError: name 'error' is not defined"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}