Changed the prevention of serialisation of exception to use instanceof