Fixed error handling in explode function