added more error trapping

Signed-off-by: Graham Chiu <compkarori@gmail.com>