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
554 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
  • 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 85

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

820 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