Use pseudovariable $exception rather than declaring an unused exception variable

Occasionally, I see catch blocks with unused exception variables.

image

Probably developer declare the variable so that they can inspect the exception while debugging, but, then forget to delete it. Since the unused variable results in a compiler warning (”The variable ‘ex’ is declared but never used”), its better to use pseudovariable $exception rather than declaring variable, if you need it just for debugging.

image

Visual studio also adds the variable to locals variables window by default.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s