本文整理汇总了C#中System.Exception.GetBaseException方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetBaseException方法的具体用法?C# Exception.GetBaseException怎么用?C# Exception.GetBaseException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.GetBaseException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: log
public static void log(string level, string comp, string msg, Exception e)
{
if (comp == null) comp = "";
if (msg == null) msg = "";
var nowms = DateTimeMs.NowMs;
var ts = nowms.ToShortDateString().PadLeft(10) + " " + nowms.ToLongTimeString().PadLeft(8) + "." + nowms.Millisecond.ToString().PadLeft(3, '0');
msg = "["+level+"] "+ ts + "["+comp+"] " + msg;
if (e != null)
{
msg += "\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
}
if (e != null && e.GetBaseException() != null && e.GetBaseException() != e)
{
e = e.GetBaseException();
msg += "BaseException:\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
}
try{
System.Console.WriteLine(msg);
#if __ANDROID__
Android.Util.Log.Error("", msg);
#endif
if (fs != null)
{
fs.Write(msg+"\n");
fs.Flush();
}
}catch(Exception){}
}
示例3: UnhandledExcp
public UnhandledExcp(Exception excp)
{
InitializeComponent();
detailText.Text = excp.ToString();
if (excp.GetBaseException() != null)
detailText.AppendText(Environment.NewLine + "--- BASE ---" + Environment.NewLine + excp.GetBaseException().ToString());
}
示例4: OnUnhandledException
private void OnUnhandledException(Exception exception)
{
MessageBox.Show(
$"An error occured:{Environment.NewLine}{exception.GetBaseException().GetType().Name}: {exception.GetBaseException().Message}",
"Oops, an error occured",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
示例5: AddValidationErrors
/// <summary>
/// Add to the model state a list of error that came from properties. If the property name
/// is empty, this one will be without property (general)
/// </summary>
/// <param name="modelState">State of the model.</param>
/// <param name="propertyErrors">The property errors.</param>
public static void AddValidationErrors(this ModelStateDictionary modelState, Exception exception)
{
if (exception is IValidationErrors)
{
foreach (var databaseValidationError in (exception as ValidationErrors).Errors)
{
modelState.AddModelError(databaseValidationError.PropertyName ?? string.Empty, databaseValidationError.PropertyExceptionMessage);
}
}
else
{
modelState.AddModelError(string.Empty, exception.Message + (exception.Message != exception.GetBaseException().Message ? "\r\n" + exception.GetBaseException().Message : ""));
}
}
示例6: FromException
public static JsonObject FromException(Exception e, bool includeStackTrace)
{
if (e == null)
throw new ArgumentNullException("e");
JsonObject error = new JsonObject();
error.Put("name", "JSONRPCError");
error.Put("message", e.GetBaseException().Message);
if (includeStackTrace)
error.Put("stackTrace", e.StackTrace);
JsonArray errors = new JsonArray();
do
{
errors.Put(ToLocalError(e));
e = e.InnerException;
}
while (e != null);
error.Put("errors", errors);
return error;
}
示例7: showError
public static void showError(Exception ex, string Infotext, Boolean ForceEnd = false)
{
string Info;
// first log the complete exception
_logger.Log(Infotext, true);
_logger.Log(ex.ToString(), true);
_logger.Log(ex.Message, true);
_logger.Log(ex.StackTrace, true);
if (ex.InnerException != null)
_logger.Log(ex.InnerException.ToString(), true);
if (Infotext.Trim().Length > 0)
Info = Infotext + Environment.NewLine + Environment.NewLine + ex.Message + Environment.NewLine;
else
Info = ex.Message + Environment.NewLine;
if (ex.InnerException != null)
Info += Environment.NewLine + ex.GetBaseException().Message;
Info += string.Format("{0}{0}(see detailed info in logfile \"{1}\")", Environment.NewLine, _logger.logPathName);
Info += "Create a dump file ?";
if (MessageBox.Show(Info, "Exception occured",MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.Yes)
Program.CreateMiniDump("RegulatedNoiseDump.dmp");
}
示例8: processError
public static void processError(Exception ex, string Infotext, bool noAsking)
{
string Info;
// first log the complete exception
_logger.Log(Infotext, true);
_logger.Log(ex.ToString(), true);
_logger.Log(ex.Message, true);
_logger.Log(ex.StackTrace, true);
if (ex.InnerException != null)
_logger.Log(ex.InnerException.ToString(), true);
if (Infotext.Trim().Length > 0)
Info = Infotext + Environment.NewLine + Environment.NewLine + ex.Message + Environment.NewLine;
else
Info = ex.Message + Environment.NewLine;
if (ex.InnerException != null)
Info += Environment.NewLine + ex.GetBaseException().Message;
Info += string.Format("{0}{0}(see detailed info in logfile \"{1}\")", Environment.NewLine, _logger.logPathName);
Info += string.Format("{0}{0}Suppress exception ? (App can be unstable!)", Environment.NewLine);
Program.CreateMiniDump("RegulatedNoiseDump_handled.dmp");
// ask user what to do
if (noAsking || (MessageBox.Show(Info, "Exception occured",MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No))
{
MessageBox.Show("Fatal error.\r\n\r\nA dump file (\"RegulatedNoiseDump_handled.dmp\" has been created in your RegulatedNoise directory. \r\n\r\nPlease place this in a file-sharing service such as Google Drive or Dropbox, then link to the file in the Frontier forums or on the GitHub archive. This will allow the developers to fix this problem. \r\n\r\nThanks, and sorry about the crash...");
Environment.Exit(-1);
}
}
示例9: Error
public Error(Exception exception, IOwinContext owinContext)
{
if (exception == null)
throw new ArgumentNullException(nameof(exception));
Exception = exception;
var baseException = exception.GetBaseException();
HostName = EnvironmentUtilities.GetMachineNameOrDefault();
TypeName = baseException.GetType().FullName;
Message = baseException.Message;
Source = baseException.Source;
Detail = exception.ToString();
User = Thread.CurrentPrincipal.Identity.Name ?? string.Empty;
Time = DateTimeOffset.Now;
StatusCode = owinContext.Response.StatusCode;
var webUser = owinContext.Authentication.User;
if (!string.IsNullOrEmpty(webUser?.Identity?.Name))
{
User = webUser.Identity.Name;
}
ServerEnvironment = owinContext.Environment.ToDictionary(pair => pair.Key, pair => pair.Value?.ToString() ?? string.Empty);
Headers = owinContext.Request.Headers.ToDictionary(pair => pair.Key, pair => pair.Value);
Query = owinContext.Request.Query.ToDictionary(pair => pair.Key, pair => pair.Value);
Cookies = owinContext.Request.Cookies.ToDictionary(pair => pair.Key, pair => pair.Value);
ApplicationName = AppDomain.CurrentDomain.FriendlyName;
}
示例10: AddException
public static void AddException(Exception exception, string comments = null, LogExceptionLevel level = LogExceptionLevel.Low)
{
if (exception == null)
return;
try
{
var baseException = exception.GetBaseException();
using (var db = new DbEntities())
{
db.InsertException(new LogException()
{
Comments = comments,
ExceptionLevel = (short)level,
InsertionTime = DateTime.Now,
Message = exception.Message,
InnerException = (exception.InnerException != null) ? exception.InnerException.Message : null,
StackTrace = exception.StackTrace,
TargetSite = (exception.TargetSite != null) ? exception.TargetSite.Name : null,
Source = exception.Source,
BaseException = (baseException != null) ? baseException.Message : null
});
}
}
catch { }
}
示例11: VLogServerSideError
/// <summary>
/// Initializes a new instance of the <see cref="VLogServerSideError"/> class.
/// from a given <see cref="Exception"/> instance and
/// <see cref="HttpContext"/> instance representing the HTTP
/// context during the exception.
/// </summary>
/// <param name="exception">The occurred server side exception</param>
public VLogServerSideError(Exception exception)
: this()
{
HttpContext context = HttpContext.Current;
if (exception != null && context != null)
{
Exception baseException = exception.GetBaseException();
this.ErrorMessage = baseException.GetErrorMessage();
this.ErrorDetails = exception.GetErrorErrorDetails();
// Sets an object of a uniform resource identifier properties
this.SetAdditionalHttpContextInfo(context);
this.SetAdditionalExceptionInfo(exception);
// If this is an HTTP exception, then get the status code
// and detailed HTML message provided by the host.
var httpException = exception as HttpException;
if (httpException != null)
{
this.ErrorCode = httpException.GetHttpCode();
VLogErrorCode errorcoderule;
if (VLog.WebErrorCodes.TryGetValue(this.ErrorCode, out errorcoderule) && !errorcoderule.ExcludeFromLogging)
{
this.AddHttpExceptionData(errorcoderule, context, httpException, errorcoderule);
}
}
}
}
示例12: BuildWebSocketError
public static string BuildWebSocketError(Exception ex)
{
ex = ex.GetBaseException();
if ((uint)ex.HResult == 0x800C000EU)
{
// INET_E_SECURITY_PROBLEM - our custom certificate validator rejected the request.
return "Error: Rejected by custom certificate validation.";
}
WebErrorStatus status = WebSocketError.GetStatus(ex.HResult);
// Normally we'd use the HResult and status to test for specific conditions we want to handle.
// In this sample, we'll just output them for demonstration purposes.
switch (status)
{
case WebErrorStatus.CannotConnect:
case WebErrorStatus.NotFound:
case WebErrorStatus.RequestTimeout:
return "Cannot connect to the server. Please make sure " +
"to run the server setup script before running the sample.";
case WebErrorStatus.Unknown:
return "COM error: " + ex.HResult;
default:
return "Error: " + status;
}
}
示例13: OnException
protected override void OnException(ExceptionContext filterContext)
{
String Errormsg = String.Empty;
Exception unhandledException = new Exception("BASE ERROR");
if (Server.GetLastError() != null)
unhandledException = Server.GetLastError();
else
unhandledException = filterContext.Exception;
Exception httpException = unhandledException as Exception;
Errormsg = "發生例外網頁:{0}錯誤訊息:{1}";
if (httpException != null /*&& !httpException.GetType().IsAssignableFrom(typeof(HttpException))*/)
{
Errormsg = String.Format(Errormsg, Request.Path + Environment.NewLine,unhandledException.GetBaseException().ToString() + Environment.NewLine);
Url = System.Web.HttpContext.Current.Request.Url.PathAndQuery;
controller = Convert.ToString(ControllerContext.RouteData.Values["controller"]);
action = Convert.ToString(ControllerContext.RouteData.Values["action"]);
area = Convert.ToString(ControllerContext.RouteData.DataTokens["area"]);
NLog.Logger logger = LogManager.GetCurrentClassLogger();
logger.Error(Url + "|controller|" + controller + "|action|" + action + "|area|" + area + "|" + Errormsg);
}
base.OnException(filterContext);
filterContext.ExceptionHandled = true;
}
示例14: WriteToEventLog
private static void WriteToEventLog(Exception ex)
{
const string source = "Health.Direct.Config.Service";
EventLogHelper.WriteError(source, ex.Message);
EventLogHelper.WriteError(source, ex.GetBaseException().ToString());
}
示例15: GetBaseCause
string GetBaseCause( Exception ex )
{
var inEx = ex.GetBaseException();
string error = null;
error = string.Format( "{1}{0}{2}", Environment.NewLine, inEx.Message, inEx.StackTrace );
return error;
}