wrap setkey in a try catch block