Error handling for register function