Fix for Titanium compiler error

Was getting a compiler error so cleaned up the logic and moved the setting of the error message into the catch method.