当前位置: 首页>>代码示例>>C#>>正文


C# Exception.GetType方法代码示例

本文整理汇总了C#中Exception.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetType方法的具体用法?C# Exception.GetType怎么用?C# Exception.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestFailed

 public TestFailed(Exception ex)
 {
     TestCase = new TestCase();
     ExceptionType = ex.GetType().FullName;
     Message = ExceptionUtility.GetMessage(ex);
     StackTrace = ExceptionUtility.GetStackTrace(ex);
 }
开发者ID:johnkg,项目名称:xunit,代码行数:7,代码来源:TestFailed.cs

示例2: logException

    public static bool logException(Exception exception)
    {
        bool status = false;
        string  logFilePathName = GetDefaultPath();
        if (!File.Exists(logFilePathName))
        {
            if (CheckForDirectory(logFilePathName))
            {
                FileStream fileStream = new FileStream(logFilePathName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                fileStream.Close();
            }
        }
        try
        {
            StreamWriter streamWriter = new StreamWriter(logFilePathName, true);

            streamWriter.WriteLine("Date        : " + DateTime.Now.ToLongTimeString());
            streamWriter.WriteLine("Time        : " + DateTime.Now.ToShortDateString());
            streamWriter.WriteLine("Error       : " + exception.Message.ToString().Trim());
            streamWriter.WriteLine("Type        : " + exception.GetType().ToString());
            streamWriter.WriteLine("********************************************************");

            streamWriter.Flush();
            streamWriter.Close();

            status = true;
        }
        catch (Exception ex)
        {
            //There was an error return null.
            Console.WriteLine(ex.ToString());
        }

        return status;
    }
开发者ID:westrada-cc,项目名称:SOA-phantom-power,代码行数:35,代码来源:Logger.cs

示例3: CmdletInvocationException

        /// <summary>
        /// Instantiates a new instance of the CmdletInvocationException class
        /// </summary>
        /// <param name="innerException">wrapped exception</param>
        /// <param name="invocationInfo">
        /// identity of cmdlet, null is unknown
        /// </param>
        internal CmdletInvocationException(Exception innerException,
                                           InvocationInfo invocationInfo)
            : base(RetrieveMessage(innerException), innerException)
        {
            if (null == innerException)
            {
                throw new ArgumentNullException("innerException");
            }
            // invocationInfo may be null

            IContainsErrorRecord icer = innerException as IContainsErrorRecord;
            if (null != icer && null != icer.ErrorRecord)
            {
                _errorRecord = new ErrorRecord(icer.ErrorRecord, innerException);
            }
            else
            {
                // When no ErrorId is specified by a thrown exception,
                //  we use innerException.GetType().FullName.
                _errorRecord = new ErrorRecord(
                    innerException,
                    innerException.GetType().FullName,
                    ErrorCategory.NotSpecified,
                    null);
            }
            _errorRecord.SetInvocationInfo(invocationInfo);
            // 2005/04/13-JonN Can't do this in an unsealed class: HelpLink = innerException.HelpLink;
            // Exception.Source is set by Throw
            // Source = innerException.Source;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:37,代码来源:ExecutionExceptions.cs

示例4: runTest

 public virtual bool runTest()
   {
   Console.Out.WriteLine( "Exception\\Co3266ctor_str.cs runTest() started." );
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strError = null;
   Exception excName1 = null;
   Exception excName2 = null;
   try {
   iCountTestcases++;
   try {
   excName1 = new Exception(null);
   }
   catch (Exception exc2) {
   iCountErrors++;
   print("E_3j3e");
   printexc(exc2);
   }
   excName1 = new Exception("This is an exception");
   iCountTestcases++;
   if(!excName1.Message.Equals("This is an exception"))
     {
     iCountErrors++;
     print("E_j23t");
     }
   iCountTestcases++;
   if(!excName1.GetType().FullName.Equals("System.Exception"))
     {
     iCountErrors++;
     print("E_3uy9");
     }
   iCountTestcases++;
   if(excName1.InnerException != null)
     {
     iCountErrors++;
     print("E_234j");
     }
   } catch (Exception exc)
     {
     iCountErrors++;
     Console.Out.WriteLine("Uncaught Exception");
     print("E_3r8s");
     printexc(exc);
     }
   if ( iCountErrors == 0 )
     {
     Console.Error.Write( "Exception\\Co3266ctor_str.cs: paSs.  iCountTestcases==" );
     Console.Error.WriteLine( iCountTestcases );
     return true;
     }
   else
     {
     Console.Error.WriteLine(  "Co3266ctor_str.cs"  );
     Console.Error.Write( "Co3266ctor_str.cs iCountErrors==" );
     Console.Error.WriteLine( iCountErrors );
     Console.Error.WriteLine( "Exception\\Co3266ctor_str.cs: FAiL!" );
     return false;
     }
   }
开发者ID:ArildF,项目名称:masters,代码行数:59,代码来源:co3266ctor_str.cs

示例5: FormatException

    static string FormatException(Exception e)
    {
        var sb = new StringBuilder();
        sb.AppendFormat("{0}: {1}", e.GetType().Name, e.Message).AppendLine()
          .AppendLine("Stack Trace:")
          .AppendLine(e.StackTrace);

        return sb.ToString();
    }
开发者ID:nerdshark,项目名称:TwitterConsole,代码行数:9,代码来源:Program.cs

示例6: printError

 public static void printError(Exception e)
 {
     string path = @"C:\Users\Public\Desktop\Failures.txt";
     //File.Delete(path);
     TextWriter tw = new StreamWriter(path, true);
     tw.WriteLine(e.GetType());
     tw.WriteLine(e.StackTrace);
     tw.Close();
 }
开发者ID:Redmancometh,项目名称:RedmanInject,代码行数:9,代码来源:Hacks.cs

示例7: TestFailed

 public TestFailed(Exception ex)
 {
     TestCase = new TestCase();
     TestCollection = new TestCollection();
     ExceptionType = ex.GetType().FullName;
     Output = String.Empty;
     Message = ExceptionUtility.GetMessage(ex);
     StackTrace = ExceptionUtility.GetStackTrace(ex);
 }
开发者ID:JayBazuzi,项目名称:xunit,代码行数:9,代码来源:TestFailed.cs

示例8: formatExceptionList

    private string formatExceptionList(Exception ex)
    {
        string currentExceptionHtml = string.Format("<br><h5 style='color:Firebrick'>{0}</h5><b>[{1}]</b><br>{2}",
                                                    ex.Message, ex.GetType().ToString(), formatStackTrace(ex.StackTrace));

        if (ex.InnerException != null)
            return formatExceptionList(ex.InnerException) + "<p>" + currentExceptionHtml;
        else
            return currentExceptionHtml;
    }
开发者ID:kiquenet,项目名称:B4F,代码行数:10,代码来源:AppErrors.aspx.cs

示例9: UnhandledError

    public UnhandledError(HttpContext context)
    {
        executionPath = context.Request.AppRelativeCurrentExecutionFilePath.Substring(1);
        timestamp = context.Timestamp;
        userName = context.User.Identity.Name;
        userHostName = context.Request.UserHostName;
        error = context.Server.GetLastError();

        if (error != null && error.GetType() == typeof(System.Web.HttpUnhandledException))
            error = error.InnerException;
    }
开发者ID:kiquenet,项目名称:B4F,代码行数:11,代码来源:UnhandledError.cs

示例10: WriteExceptionText

        private static bool WriteExceptionText(StringBuilder sb, Exception e)
        {
            if (e == null)
                return false;

            sb.Append(e.GetType().Name);
            sb.Append(Environment.NewLine);
            sb.Append(e.Message);
            sb.Append(Environment.NewLine);

            return true;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:12,代码来源:Tracing.cs

示例11: displayException

    protected void displayException(Exception ex)
    {
        lbError.Text += "\n<h2>" + ex.Message + "</h2>";
        lbError.Text += "\n<p class=\"error\">";
        lbError.Text += "\n<h4>Typ</h4>" + ex.GetType().ToString();
        lbError.Text += "\n<h4>Source</h4>" + ex.Source;
        lbError.Text += "\n<h4>StackTrace</h4>" + ex.StackTrace.Replace(" at ", "<br />");
        lbError.Text += "\n</p>\n";

        if (ex.InnerException != null)
            displayException(ex.InnerException);
    }
开发者ID:RPGPlanner,项目名称:RPGPlanner,代码行数:12,代码来源:ErrorPage.aspx.cs

示例12: GetSequencePoint

 static SequencePoint GetSequencePoint(Exception exception)
 {
     var exceptionType = exception.GetType();
     var sequencePointProperty = exceptionType.GetProperty("SequencePoint", BindingFlags.Public | BindingFlags.Instance);
     var sequencePoint = (SequencePoint) sequencePointProperty?.GetValue(exception, null);
     if (sequencePoint != null)
     {
         return sequencePoint;
     }
     var sequencePointField = exceptionType.GetField("SequencePoint", BindingFlags.Public|BindingFlags.Instance);
     return (SequencePoint) sequencePointField?.GetValue(exception);
 }
开发者ID:TylerBrinkley,项目名称:Fody,代码行数:12,代码来源:ExceptionExtensions.cs

示例13: ExceptionSurrogate

        internal ExceptionSurrogate(Exception exception)
        {
            Contract.Assert(exception != null);

            Message = exception.Message;
            StackTrace = exception.StackTrace;
            if (exception.InnerException != null)
            {
                InnerException = new ExceptionSurrogate(exception.InnerException);
            }
            ExceptionType = exception.GetType().FullName;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:12,代码来源:ExceptionSurrogate.cs

示例14: ProcessException

    private void ProcessException(Exception ex, string exLevel)
    {
        lErrorInfo.Text += "<a href=\"#\" class=\"exception-type label\">" + exLevel + ex.GetType().Name + " in " + ex.Source + "</a>";
        lErrorInfo.Text += "<div class=\"stack-trace\"><strong>Stack Trace</strong><br>" + ex.StackTrace + "</div>";

        // check for inner exception
        if ( ex.InnerException != null )
        {
            //lErrorInfo.Text += "<p /><p />";
            ProcessException( ex.InnerException, "-" + exLevel  );
        }
    }
开发者ID:rowlek,项目名称:Rock-ChMS,代码行数:12,代码来源:error.aspx.cs

示例15: runTest

 public virtual bool runTest()
   {
   Console.Out.WriteLine( "Co3265ctor.cs runTest() started." );
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Exception excName1 = null;
   try {
   excName1 = new Exception();
   iCountTestcases++;
   if(!excName1.Message.Equals("Exception of type 'System.Exception' was thrown."))
     {
     if(CultureInfo.CurrentCulture.Equals(new CultureInfo("en-US")))
       {
       iCountErrors++;
       Console.WriteLine(excName1.Message + " Expected " + "An exception of type 'System.Exception' was thrown.");
       print("E_j23t");
       }
     }
   iCountTestcases++;
   if(!excName1.GetType().FullName.Equals("System.Exception"))
     {
     iCountErrors++;
     print("E_3uy9 exc=="+excName1.ToString());
     }
   iCountTestcases++;
   if(excName1.InnerException != null)
     {
     iCountErrors++;
     print("E_234j");
     }
   } catch (Exception exc)
     {
     iCountErrors++;
     Console.Out.WriteLine("Uncaught Exception");
     print("E_3r8s");
     printexc(exc);
     }
   if ( iCountErrors == 0 )
     {
     Console.Error.Write( "Co3265ctor.cs: paSs.  iCountTestcases==" );
     Console.Error.WriteLine( iCountTestcases );
     return true;
     }
   else
     {
     Console.Error.WriteLine(  "Co3265ctor.cs"  );
     Console.Error.Write( "Co3265ctor.cs iCountErrors==" );
     Console.Error.WriteLine( iCountErrors );
     Console.Error.WriteLine( "Co3265ctor.cs: FAiL!" );
     return false;
     }
   }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:52,代码来源:co3265ctor.cs


注:本文中的Exception.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。