Fix all catch statements: use a reference so we don't make a copy of an exception (which can go wrong itself), and use base classes where possible to catch as many types of exceptions as possible