Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 966535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:10:19+00:00 2026-05-16T02:10:19+00:00

When copying and pasting a bit of sample code from MSDN, I came up

  • 0

When copying and pasting a bit of sample code from MSDN, I came up with the error in the title – Variable ” hides a variable in an enclosing block,

All I copied was a very basic example of a try loop.

As it says in the suggestion “A common cause for this error is the use of Catch e As Exception inside an event handler. If this is the case, name the Catch block variable ex rather than e.”

So, I did that, changed both e to ex and it worked, however, I don’t understand why this doesn’t cause the same error.

Can someone please explain better what the error is and why e causes it, and ex doesn’t?

edit –

code example…

    Try
    Catch e As Exception
        msgbox(e.Message)
    End Try

.

    Try
    Catch ex As Exception
        msgbox(ex.Message)
    End Try

What I don’t understand is why the first one causes the problem and the second one doesn’t, to me, it is like… Using apples above, apple below – saying you can’t use the same thing in both places, then changing both to oranges and suddenly letting it work. Surely the second is doing the same as the first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:10:19+00:00Added an answer on May 16, 2026 at 2:10 am

    You might want to paste the full code for the error to confirm but I would assume that the event handler defines a parameter called “e”. Then when you put in the catch block it tries to define “e” as well, causing the error in question. Of course when the catch is defining “ex” instead of “e” then there is no name clash happening so it works.

    Edit: Edited to add clearer example of what I assume is the breoken code.

    I assume your breaking code looks like:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
        Catch e As Exception
            msgbox(e.Message)
        End Try
    End Sub
    

    You can see the two declarations of e, one in ByVal e As System.EventArgs and the other at Catch e As Exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer here's another way, use nawk nawk '/ADDRESS/{$0=$0" PROTOCOL"}1' file May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Note that A::Ptr is private in your sample. You should… May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer private void tvwACH_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e) { string strFile =… May 16, 2026 at 6:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

When copying a project over from another machine I got this error, a clean/rebuild
I'm still groping around a bit with Castle Windsor. At the moment all my
Instead of copying php.ini files over from old PHP versions whenever I upgrade PHP,
I am copying a mutable array like this: //copy players' info into playerList from
I am using core data and am generating classes from my data model. I
I have a question about using os.execvp in Python. I have the following bit
Is there a tool to import/convert COM type libraries into C# code rather than
How do people normally manage copying a list of large objects around? Here's my
I need to have a Python CGI script do some stuff (a little bit
Hey everyone... I'm not too familiar with PHP... but I have PHP code that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.