Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Try Catch (Exception e) 'e' cannot be decalred in this scope because it would give a different meaning to 'e'

Posted on 2011-03-23
7
Medium Priority
?
560 Views
Last Modified: 2013-12-17
I am trying to delete a record using LINQ and then submit the changes in a Try/Catch statement but it will not let me trap for errors.  Can someone tell me what I am missing.   Here is my code:


DataClasses1DataContext dcDataClass1 = new DataClasses1DataContext();


            PatientMed myPatientMed = new PatientMed();

            MyGlobalVars.DeleteRecordKey = this.UltraWebGridSelectedMeds.DisplayLayout.SelectedRows[0].Cells.FromKey("PatMedsKey").Text;

            var SelectedMedsResult = from selectedmedsdata in dcDataClass1.PatientMeds
                                     where selectedmedsdata.PatMedsKey.ToString() == MyGlobalVars.DeleteRecordKey
                                     select selectedmedsdata;


            foreach (var selectedmedsresultrecord in SelectedMedsResult)
            {
                

                dcDataClass1.PatientMeds.DeleteOnSubmit(selectedmedsresultrecord);

                try
                {
                    dcDataClass1.SubmitChanges();

                }
                catch (Exception e)  <<<  ------------ error occurs here
                {
                    // --
                }

Open in new window

0
Comment
Question by:kwh3856
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Author Comment

by:kwh3856
ID: 35203780
Actual error message:

Error 1 A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else      
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35203791
Most likely the EVENT that this code is in has a PARAMETER that is called "e".

All you need to do is change the name of your Exception variable in the Catch block to something else.

Change:

                catch (Exception e)  
                {
                    // --
                }

To:

                catch (Exception e2)  
                {
                    // ... use "e2" in here ...
                }
0
 

Author Comment

by:kwh3856
ID: 35203792
I think it may be referring to the following code but still not sure how to correct it.  Tried to change it to (Exception x) but then got the error "The variable 'x' is declared but never used"



protected void UltraWebGridSelectedMeds_SelectedRowsChange(object sender, SelectedRowsEventArgs e)
        {

            DataClasses1DataContext dcDataClass1 = new DataClasses1DataContext();

Open in new window

0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35203798
This is simply a WARNING:

    "The variable 'x' is declared but never used"

that means you are not using the 'x' variable anywhere in the Catch{} block.  It should still compile and run fine.
0
 

Author Comment

by:kwh3856
ID: 35203803
ok i will try - I did not notice it was only a warning.
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35203805
have you uses x in catch yet?

for ex.

System.Console.WriteLine("Error message : " + x.Message);
0
 

Author Closing Comment

by:kwh3856
ID: 35203853
Thank you.  That was exactly it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question