The only reason you would use try...catch for this situation would be if it is possible for the if () to fail *or* to succeed incorrectly.
In other words, suppose that
Code:
if ( style.styleSheet )
returns a non-null value in some browser other than MSIE and yet the line
Code:
style.styleSheet.cssText = "...";
would perhaps fail in that other browser.
If that's never the case, then clearly the "if" version is more efficient.
**********
FWIW, I personally abhor code such as
Code:
if ( style.styleSheet )
I *MUCH* prefer to write
Code:
if ( style.styleSheet != null )
I know they mean the same thing, thanks to the sloppiness of JavaScript, but they don't have the same "feel". I think that if() tests should always be based on boolean expressions. For the same reason, I detest code that does:
Code:
var i = 7;
while ( i ) {
...
--i;
}
What does it cost to use
or
which are *SO* much more clear in meaning???