wrap all C interface code with try-catch block