Don't bother with the checking part, just cast it and catch exceptions.