Error handle
This MR handles some exception, recovers where it can, adds some utility functions that are used upstream and does some general refactoring along the way.
This MR handles some exception, recovers where it can, adds some utility functions that are used upstream and does some general refactoring along the way.