none
How to know source function and source data when debug on visual studio 2015 RRS feed

  • Question

  • Problem


    How to know that subfunction2 come from subfunction1 or with another meaning 

    it source of subfunction2 exist on subfunction1 ?

    I work on csharp language on visual studio 2015 windows form

    I implement and develop big module and have more functions nested on another functions

    i need when make breakpoint to function to know this function come from any place or 

    with another way what calling to this function done  before it called and data on function 

    come from any place I ask this question because i work on project have more functions 

    nested on each others and in different places and different files 

    Public Datatable MainFunction(string data)
    {
    datatable dt1=SubFunction1(string data);
    }
    Public Datatable SubFunction1(string data)
    {
    datatable dt2=SubFunction2(string data);
    }
    Public Datatable SubFunction2(string data)
    {
    
    }
    

    
    when debug and found exception on SubFunction2
    
    How to know that subfunction2 come from subfunction1 or with another meaning 
    
     source of subfunction2 exist on subfunction1
    Friday, February 8, 2019 1:54 AM

Answers

  • When you debug and use breakpoints and it is hit you can see call stack window to see call chain.
    Friday, February 8, 2019 10:19 AM

All replies

  • When an Exception is thrown, you can see where it happened by using the Exception's StackTrace:

    public DataTable SubFunction2 (string data)
    {
        try
        {
            // your code here
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: {0}\r\n StackTrace: {1}", ex.Message, ex.StackTrace);
        }
    }
    


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, February 8, 2019 2:11 AM
    Moderator
  • You could use [CallerMemberName] e.g.

    private void StartsHere()
    {
        SomeMethod(12);
    }
    
    private void SomeMethod(int identifier, [CallerMemberName] string name = "")
    {
        Console.WriteLine($"Identifier is {identifier} from {name}");
    }

    Result

    Identifier is 12 from StartsHere

    So then you can check the name of the caller against a string name.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, February 8, 2019 3:04 AM
    Moderator
  • When it stops at breakpoint, go to menu, Debug, Windows, Call Stack. It will show the previous locations.

    See also the Call Hierarchy command in View menu.

    Friday, February 8, 2019 6:11 AM
  • When you debug and use breakpoints and it is hit you can see call stack window to see call chain.
    Friday, February 8, 2019 10:19 AM