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
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
ok i will try - I did not notice it was only a warning.
0
 
LVL 11

Expert Comment

by:JoeNuvo
Comment Utility
have you uses x in catch yet?

for ex.

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

Author Closing Comment

by:kwh3856
Comment Utility
Thank you.  That was exactly it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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 use and create keystrokes in Netbeans IDE 8.0 for Windows.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now