本文整理汇总了C#中System.Exception.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetType方法的具体用法?C# Exception.GetType怎么用?C# Exception.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public void Log(Exception ex)
{
string path = @"Errors.txt";
if(File.Exists(path))
{
using (StreamWriter log = File.AppendText(path))
{
log.WriteLine("Error logged:");
log.WriteLine(ex.GetType());
log.WriteLine(ex.Message);
log.WriteLine(ex.StackTrace);
log.WriteLine();
}
}
else
{
using (StreamWriter log = File.CreateText(path))
{
log.WriteLine(ex.GetType());
log.WriteLine(ex.StackTrace);
log.WriteLine();
}
}
}
示例2: ProvideFault
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
JObject json = new JObject();
json.Add(JsonRpcConstants.ResultKey, null);
JsonRpcException jsonException = error as JsonRpcException;
if (jsonException != null)
{
json.Add(JsonRpcConstants.ErrorKey, jsonException.JsonException);
}
else
{
JObject exceptionJson = new JObject
{
{ "type", error.GetType().FullName },
{ "message", error.Message },
};
JObject temp = exceptionJson;
while (error.InnerException != null)
{
error = error.InnerException;
JObject innerJson = new JObject
{
{ "type", error.GetType().FullName },
{ "message", error.Message },
};
temp["inner"] = innerJson;
temp = innerJson;
}
json.Add(JsonRpcConstants.ErrorKey, exceptionJson);
}
fault = JsonRpcHelpers.SerializeMessage(json, fault);
}
示例3: Translate
public string Translate(Exception e)
{
//TODO (CR April 2011): Figure out how to share the Exception Policies for these messages ...
//Current ExceptionHandler/Policy design just doesn't work for this at all.
if (e.GetType().Equals(typeof(InUseLoadStudyException)))
return ImageViewer.SR.MessageLoadStudyFailedInUse;
if (e.GetType().Equals(typeof(NearlineLoadStudyException)))
{
return ((NearlineLoadStudyException)e).IsStudyBeingRestored
? ImageViewer.SR.MessageLoadStudyFailedNearline : ImageViewer.SR.MessageLoadStudyFailedNearlineNoRestore;
}
if (e.GetType().Equals(typeof(OfflineLoadStudyException)))
return ImageViewer.SR.MessageLoadStudyFailedOffline;
if (e.GetType().Equals(typeof(NotFoundLoadStudyException)))
return ImageViewer.SR.MessageLoadStudyFailedNotFound;
if (e.GetType().Equals(typeof(LoadStudyException)))
return SR.MessageStudyCouldNotBeLoaded;
if (e is LoadMultipleStudiesException)
return ((LoadMultipleStudiesException)e).GetUserMessage();
if (e.GetType().Equals(typeof(NoVisibleDisplaySetsException)))
return ImageViewer.SR.MessageNoVisibleDisplaySets;
if (e.GetType().Equals(typeof(PatientStudiesNotFoundException)))
return SR.MessagePatientStudiesNotFound;
if (e.GetType().Equals(typeof(AccessionStudiesNotFoundException)))
return SR.MessageAccessionStudiesNotFound;
if (e.GetType().Equals(typeof(InvalidRequestException)))
return e.Message;
if (e.GetType().Equals(typeof(PermissionDeniedException)))
return e.Message;
return null;
}
示例4: HandleException
public CommandResult HandleException(Exception ex)
{
if (_handlerConfigurationCollection.ContainsValueForType(ex.GetType()))
return _handlerConfigurationCollection.GetForType(ex.GetType())(ex);
return _handlerConfigurationCollection.GetForType(typeof(Exception))(ex);
}
示例5: UnhandledException
public ActionResult UnhandledException(Exception exception)
{
if (exception == null)
{
return UnknownError();
}
if (exception.GetType().Equals(typeof(HttpException)))
{
HttpException httpException = (HttpException)exception;
Response.StatusCode = httpException.GetHttpCode();
switch (httpException.GetHttpCode())
{
case 403:
return Http403(httpException);
case 404:
return Http404(httpException);
}
}
if (exception.GetType().Equals(typeof(EntityCommandExecutionException)))
{
//TODO: smartly handle database errors.
}
return View(exception);
}
示例6: LogError
/// -------------------------------------------------------------------
/// <summary>
/// Report that the test had an error
/// </summary>
/// -------------------------------------------------------------------
public static void LogError(Exception exception)
{
// Our test framework calls using Invoke, and throw is returned
if (exception is TargetInvocationException)
exception = exception.InnerException;
// If a test catches the exception, and then rethrows the excpeption later, it uses "RETHROW"
// to allow this global exception handler to peel this rethrow and analyze the actual exception.
if (exception.Message == "RETHROW")
exception = exception.InnerException;
if (exception.GetType() == typeof(InternalHelper.Tests.KnownProductIssueException))
{
_knownIssues++;
_currentLogger.Log(new ExceptionInfo(exception, false, true, false));
LogPass();
}
else if (exception.GetType() == typeof(InternalHelper.Tests.IncorrectElementConfigurationForTestException))
{
_incorrectConfigurations++;
_currentLogger.Log(new CommentInfo(exception.Message));
LogPass();
}
else if (exception.GetType() == typeof(InternalHelper.Tests.TestErrorException))
{
_currentLogger.Log(new ExceptionInfo(exception));
_currentLogger.Log(new TestResultInfo(TestResultInfo.TestResults.Failed));
}
else
{
LogUnexpectedError(exception);
}
}
示例7: Handle
/// <summary>
/// Displays exception information. Should be called from try...catch handlers
/// </summary>
/// <param name="ex">Exception object to handle</param>
new public static void Handle(Exception ex)
{
if (ex != null)
{
if (ex is System.Net.WebException)
{
MessageBox.Show(ex.Message, "Network access error. Please try again later", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
ErrorHandler handler = new ErrorHandler();
handler.txtError.Text = ex.Message;
handler.txtDetails.Text = "{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = Exception: " + ex.GetType().Name + "\r\nMessage: " +
ex.Message + "\r\nCall stack:" + ex.StackTrace + "\r\n~~~~\r\n | OS = " + Environment.OSVersion.ToString() + "\r\n | version = " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
handler.txtDetails.Text += "\r\n}}";
handler.textBox1.Text = "AWB Updater encountered " + ex.GetType().Name;
handler.ShowDialog();
}
}
}
示例8: Fatal
public static void Fatal(Exception ex, string Source)
{
HttpContext.Current.Response.StatusCode = 500;
try
{
try
{
if (ex.GetBaseException().GetType().ToString() == "MySql.Data.MySqlClient.MySqlException")
MySqlConnection.ClearAllPools();
}
catch { }
Fatal("[" + ex.GetBaseException().GetType().ToString() + "]" + ex.GetBaseException().Message, ex.GetBaseException().ToString(), "Fatal " + ex.GetBaseException().GetType().ToString(), Source);
}
catch
{
try
{
if (ex.GetType().ToString() == "MySql.Data.MySqlClient.MySqlException")
MySqlConnection.ClearAllPools();
}
catch { }
Fatal("[" + ex.GetType().ToString() + "]" + ex.Message, ex.ToString(), "Fatal " + ex.GetType().ToString(), Source);
}
}
示例9: Unwrap
public static Exception Unwrap(Exception exception)
{
if (exception == null)
{
throw new ArgumentNullException("exception");
}
if (exception.InnerException == null)
{
return exception;
}
// Always return the inner exception from a target invocation exception
if (exception.GetType() == typeof (TargetInvocationException))
{
return exception.InnerException;
}
// Flatten the aggregate before getting the inner exception
if (exception.GetType() == typeof (AggregateException))
{
return ((AggregateException) exception).Flatten().InnerException;
}
return exception;
}
示例10: IsFatal
public static bool IsFatal(Exception exception)
{
while (exception != null)
{
if (exception.GetType().Name == "FatalException" ||
(exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
exception is ThreadAbortException ||
exception.GetType().Name == "FatalInternalException")
{
return true;
}
// These exceptions aren't themselves fatal, but since the CLR uses them to wrap other exceptions,
// we want to check to see whether they've been used to wrap a fatal exception. If so, then they
// count as fatal.
if (exception is TypeInitializationException ||
exception is TargetInvocationException)
{
exception = exception.InnerException;
}
else
{
break;
}
}
return false;
}
示例11: SetError
public void SetError(Exception exception)
{
HasError = true;
ExceptionType = exception.GetType();
if (ExceptionType == typeof(AggregateException))
{
exception = GetInitialException(exception);
ExceptionType = exception.GetType();
}
foreach (var stackTrace in _stackTraceList.AsEnumerable().Reverse())
{
StackTrace += stackTrace + "\n";
}
if (ExceptionType == typeof(HttpRequestException))
{
ExceptionTitle = "Error fetching data";
ExceptionOriginalMessage = exception.Message;
ExceptionMessage = exception.Message + " Please check your connection and try again, cached data will still show up in the app.";
}
else
{
ExceptionTitle = "Unhandleded error occured";
ExceptionOriginalMessage = exception.Message;
ExceptionMessage = exception.Message;
}
}
示例12: FormatException
/// <summary>
/// INTERNAL
/// </summary>
/// <param name="error">The exception to format.</param>
public static string FormatException(Exception error)
{
if (error == null)
throw new ArgumentNullException("error");
//?? _090901_055134 Regex is used to fix bad PS V1 strings; check V2
Regex re = new Regex("[\r\n]+");
string info =
error.GetType().Name + ":" + Environment.NewLine +
re.Replace(error.Message, Environment.NewLine) + Environment.NewLine;
// get an error record
if (error.GetType().FullName.StartsWith("System.Management.Automation.", StringComparison.Ordinal))
{
object errorRecord = GetPropertyValue(error, "ErrorRecord");
if (errorRecord != null)
{
// process the error record
object ii = GetPropertyValue(errorRecord, "InvocationInfo");
if (ii != null)
{
object pm = GetPropertyValue(ii, "PositionMessage");
if (pm != null)
//?? 090517 Added Trim(), because a position message starts with an empty line
info += re.Replace(pm.ToString().Trim(), Environment.NewLine) + Environment.NewLine;
}
}
}
if (error.InnerException != null)
info += Environment.NewLine + FormatException(error.InnerException);
return info;
}
示例13: buildTreeLayer
void buildTreeLayer(Exception e, TreeViewItem parent)
{
String exceptionInformation = "\n\r\n\r" + e.GetType().ToString() + "\n\r\n\r";
parent.DisplayMemberPath = "Header";
parent.Items.Add(new TreeViewStringSet() { Header = "Type", Content = e.GetType().ToString() });
System.Reflection.PropertyInfo[] memberList = e.GetType().GetProperties();
foreach (PropertyInfo info in memberList)
{
var value = info.GetValue(e, null);
if (value != null)
{
if (info.Name == "InnerException")
{
TreeViewItem treeViewItem = new TreeViewItem();
treeViewItem.Header = info.Name;
buildTreeLayer(e.InnerException, treeViewItem);
parent.Items.Add(treeViewItem);
}
else
{
TreeViewStringSet treeViewStringSet = new TreeViewStringSet() { Header = info.Name, Content = value.ToString() };
parent.Items.Add(treeViewStringSet);
exceptionInformation += treeViewStringSet.Header + "\n\r\n\r" + treeViewStringSet.Content + "\n\r\n\r";
}
}
}
ExceptionInformationList.Add(exceptionInformation);
}
示例14: ErrorReport
public ErrorReport(string s, Exception ex)
{
InitializeComponent();
var message = new StringBuilder();
message.AppendLine("MTMCL, version " + MeCore.version);
message.AppendLine(s);
message.AppendLine("\n\n-----------------ERROR REPORT----------------------\n");
message.AppendFormat("Target Site: {0}", ex.TargetSite).AppendLine();
message.AppendFormat("Error Type: {0}", ex.GetType()).AppendLine();
message.AppendFormat("Messge: {0}", ex.Message).AppendLine();
foreach (DictionaryEntry data in ex.Data)
message.AppendLine(string.Format("Key:{0}\nValue:{1}", data.Key, data.Value));
message.AppendLine(ex.StackTrace);
var iex = ex;
while (iex.InnerException != null)
{
message.AppendLine("------------Inner Exception------------");
iex = iex.InnerException;
message.AppendFormat("Target Site: {0}", ex.TargetSite).AppendLine();
message.AppendFormat("Error Type: {0}", ex.GetType()).AppendLine();
message.AppendFormat("Messge: {0}", ex.Message).AppendLine();
foreach (DictionaryEntry data in ex.Data)
message.AppendLine(string.Format("Key:{0}\nValue:{1}", data.Key, data.Value));
message.AppendLine("StackTrace");
message.AppendLine(iex.StackTrace);
}
CreateLogInfoPart(message);
txtMes.Text = message.ToString();
}
示例15: getErrorInfo
protected StringBuilder getErrorInfo( HttpApplication app ) {
Exception exLast = app.Server.GetLastError();
ex = exLast.GetBaseException();
ex = wrapStaticFileException( ex );
HttpRequest req = getRequest( app );
if (req == null) {
StringBuilder sb = new StringBuilder();
sb.AppendLine( "ex.Message=" + ex.Message );
sb.AppendLine( "ex.Type=" + ex.GetType().FullName );
sb.AppendLine( "ex.Version=" + MvcConfig.Instance.Version );
sb.AppendLine( "ex.Source=" + getExSource( ex ) );
sb.AppendLine( "ex.StackTrace=" + getExStackTrace( ex, exLast ) );
return sb;
}
else {
StringBuilder sb = new StringBuilder();
sb.AppendLine( "url=" + req.Url.ToString() );
sb.AppendLine( "ex.Message=" + ex.Message );
sb.AppendLine( "ex.Type="+ ex.GetType().FullName );
sb.AppendLine( "ex.Version=" + MvcConfig.Instance.Version );
appendPostValues( "ex.PostedValue=", req.Form, sb );
sb.AppendLine( "ex.Source=" + getExSource( ex ) );
sb.AppendLine( "ex.StackTrace=" + getExStackTrace( ex, exLast ) );
return sb;
}
}