첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;
using System.Diagnostics;
using System.Reflection;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 실행하기 - Execute(count)

        /// <summary>
        /// 실행하기
        /// </summary>
        /// <param name="count">카운트</param>
        private static void Execute(int count)
        {
            if(count > 0)
            {
                Execute(count - 1);
            }
            else
            {
                throw new Exception();
            }
        }

        #endregion
        #region 예외 호출 스택 출력하기 - PrintExceptionCallStack(exception)

        /// <summary>
        /// 예외 호출 스택 출력하기
        /// </summary>
        /// <param name="exception">예외</param>
        private static void PrintExceptionCallStack(Exception exception)
        {
            StackTrace stackTrace = new StackTrace(exception, true);

            StackFrame[] stackFrameArray = stackTrace.GetFrames();

            foreach (StackFrame stackFrame in stackFrameArray)
            {
                MethodBase methodBase = stackFrame.GetMethod();

                Console.WriteLine($"{methodBase.ReflectedType.FullName}.{methodBase.Name} line {stackFrame.GetFileLineNumber()}");
            }
        }

        #endregion
        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            try
            {
                Execute(5);
            }
            catch(Exception exception)
            {
                PrintExceptionCallStack(exception);
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요