Use try/except instead of if/else for version compatibility