Managing exceptions thrown in different parts of the code