本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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 );
}
}
示例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;
}
}