Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

C#
namespace trycatchtest
{
    class Program
    {
        static void Main(string[] args)
        {
            tryTest t = new tryTest(1);
        }
    }

    public class tryTest
    {

        public tryTest(int a)
        {
            try
            {

                string filePath = @"D:\FTP Root\BUS_01_Argese\CDR\Template1\1Row.csv";
                var orders = System.IO.File.ReadAllLines(filePath).Skip(1);
                var query = from line in orders.AsParallel()
                            select new
                            {
                                CallingNumber = GetCDRColumn()
                            };




                var col = query.ToList();

            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }

        private string GetCDRColumn()
        {
            try
            {
                throw new Exception("My error");

                return string.Empty;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}


this is my code i handled error using try catch but when running this program also showing error was unhadled by used code but this happen only i read from file.
Posted

1 solution

I can't obviously see where an exception could get through your handlers, but i bnotice that some of your code is not there anyway - otherwise it wouldn't compile (CallingNumber is not declared). It may be other code which is throwing the exception.

In VS, on the menu bar, select "Debug...Exceptions"
In the dialog that appears, make sure there is a tick in every box under both "Thrown" and "User-unhandled".
Press OK.
Now when your program throws an exception, the debugger will break on the line that causes it, whether you have a handler or not. You should be able to work out where the problem is from there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900