locked
What can cause Unhanded exception ? RRS feed

  • Question

  • hello all i got this code here thanks to someone else helping me on this form 

    i just dont understand what unhanded exception means or what could trigger it to do this 

    this is the code i have 

     private void button36_Click(object sender, EventArgs e)
            {
                string weapons1 = Launcher.GetRawDirectory() + "\\weapons\\sp";
                string mod1 = Launcher.GetModsDirectory(this.modName) + "weapons\\sp";
                List<string> fileList = new DirectoryInfo(weapons1).GetFiles().Where(x => x.CreationTime.Date == DateTime.Today)
                                                         .Select(x => x.FullName)
                                                         .ToList();
                foreach (var file in fileList)
                {
                    try
                    {
                        //do File.Move or File.Copy                     
                        File.Copy(weapons1, mod1, true); //overwrite flag is true
                    }
                    catch (NotImplementedException p)
                    {
                        MessageBox.Show(p.Message);
                    }
                }
            }

    and when i push the button copy weapon files ( and yes  i made sure there was a weapon file that was created today ) 

    it throws this error 

    and im not sure why it hits this error or even gets here i tried debugging it and stepping in but it just hits that even if i break point the all the lines so it confuses me 

    thanks in advance elfenliedtopfan5

    Saturday, June 6, 2015 10:20 PM

Answers

  • i just dont understand what unhanded exception means or what could trigger it to do this 

    this is the code i have 

    private void button36_Click(object sender, EventArgs e) { string weapons1 = Launcher.GetRawDirectory() + "\\weapons\\sp"; string mod1 = Launcher.GetModsDirectory(this.modName) + "weapons\\sp";

    ... }


    >string mod1 = Launcher.GetModsDirectory(this.modName) + "weapons\\sp";

    The above line calls the GetModsDirectory member method, which has no code in it except

    throw new NotImplementedException();

    So what did you expect would happen?

    - Wayne

    • Marked as answer by Caillen Tuesday, June 16, 2015 12:24 PM
    Sunday, June 7, 2015 1:41 AM
  • When you ask the compiler to implement an interface, it just puts in all the functions with a single "throw new NotImplementedException();" command.
    That way it is guaranteed that the function returns something (exception 100% of the time is a valid return value for the compiler!).
    And everybody that uses your class knows you failed at actually putting in ANY code for that functions, as you said you WOULD when impleneting that interface.

    Unhandeled Exception simply means "Your code did not catch it, so the .NET runtime had to catch it, expose it and close your application for you".

    Proper Exception handling is a tricky business. Actually doing to much can be more of an issue as doing none at all:

    Exception Handling Best Practices in .NET - CodeProject

    Vexing exceptions - Fabulous Adventures In Coding - Site Home - MSDN Blogs

    • Marked as answer by Caillen Tuesday, June 16, 2015 12:24 PM
    Sunday, June 7, 2015 8:56 AM

All replies

  • i just dont understand what unhanded exception means or what could trigger it to do this 

    What it means is a line of code through an exception, and  the line of code that through the exception is not within a try/catch block. So therefore the exception is unhandled

    Sunday, June 7, 2015 1:31 AM
  • i just dont understand what unhanded exception means or what could trigger it to do this 

    this is the code i have 

    private void button36_Click(object sender, EventArgs e) { string weapons1 = Launcher.GetRawDirectory() + "\\weapons\\sp"; string mod1 = Launcher.GetModsDirectory(this.modName) + "weapons\\sp";

    ... }


    >string mod1 = Launcher.GetModsDirectory(this.modName) + "weapons\\sp";

    The above line calls the GetModsDirectory member method, which has no code in it except

    throw new NotImplementedException();

    So what did you expect would happen?

    - Wayne

    • Marked as answer by Caillen Tuesday, June 16, 2015 12:24 PM
    Sunday, June 7, 2015 1:41 AM
  • When you ask the compiler to implement an interface, it just puts in all the functions with a single "throw new NotImplementedException();" command.
    That way it is guaranteed that the function returns something (exception 100% of the time is a valid return value for the compiler!).
    And everybody that uses your class knows you failed at actually putting in ANY code for that functions, as you said you WOULD when impleneting that interface.

    Unhandeled Exception simply means "Your code did not catch it, so the .NET runtime had to catch it, expose it and close your application for you".

    Proper Exception handling is a tricky business. Actually doing to much can be more of an issue as doing none at all:

    Exception Handling Best Practices in .NET - CodeProject

    Vexing exceptions - Fabulous Adventures In Coding - Site Home - MSDN Blogs

    • Marked as answer by Caillen Tuesday, June 16, 2015 12:24 PM
    Sunday, June 7, 2015 8:56 AM