Slightly improved the error handling, so that to :
- avoid some infinite loops
- display the error message when an unexpected error occurs