# Catch exception of resources in chef ? (if resource failed, then do resource instead)

**URL:** <https://discourse.chef.io/t/catch-exception-of-resources-in-chef-if-resource-failed-then-do-resource-instead/6633>\
**Category:** Chef Infra (archive)\
**Created:** [May 6, 2015, 5:54pm UTC](https://discourse.chef.io/t/catch-exception-of-resources-in-chef-if-resource-failed-then-do-resource-instead/6633 "2015-05-06T17:54:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Medya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/medya/32/96_2.png) [@Medya](https://discourse.chef.io/u/Medya)\
**Post date:** [May 6, 2015, 5:54pm UTC](https://discourse.chef.io/t/catch-exception-of-resources-in-chef-if-resource-failed-then-do-resource-instead/6633/1 "2015-05-06T17:54:23Z")

</div>

is there a way to catch exceptions of a chef resource ?

like if this resource fails to compile or converge, then this do this other  
resource instead ?

while my question is about all resources, I am thinking an example of using  
it in Machine resource

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 6, 2015, 5:59pm UTC](https://discourse.chef.io/t/catch-exception-of-resources-in-chef-if-resource-failed-then-do-resource-instead/6633/2 "2015-05-06T17:59:36Z")

</div>

Ignore failure attribute suppress the exception. There's a event handler  
hook to detect this and do something. You combine these two to write an  
hwrp/lwrp that does what you want. Declare the failure resource with  
nothing action, the alter it via event handler  
On May 6, 2015 10:55 AM, "Medya" [medya.gh@gmail.com](mailto:medya.gh@gmail.com) wrote:

> is there a way to catch exceptions of a chef resource ?
> 
> like if this resource fails to compile or converge, then this do this  
> other resource instead ?
> 
> while my question is about all resources, I am thinking an example of  
> using it in Machine resource
