place getcode() in try block