perf: move try catch to inner function