Use a nested try block

http://ideone.com/7ITiXF