This line of code will tell you if a temp table exists in the temp database, so you avoid all those errors..
Tested in SQL 2000 & 2005: