added protection against exceptions, for #1786