spraff spraff - 3 months ago 6
Javascript Question

Why does Google Closure think Exception is undefined?

I tried running Google's Closure Compiler on my code with

-W VERBOSE


This simple statement

throw new Exception ("hello");


yields an error

variable Exception is undeclared


I thought
Exception
was standard. Is Closure wrong, or should I be declaring Exception somehow before throwing it? (My code runs fine in Firefox.)

Answer

You should be throwing Error's instead of Exception's:

throw new Error('hello');

(throw new Exception() doesn't work in my Firefox, not sure why it works for you)