本文整理汇总了C#中System.Exception类的典型用法代码示例。如果您正苦于以下问题:C# Exception类的具体用法?C# Exception怎么用?C# Exception使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Exception类属于System命名空间,在下文中一共展示了Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteLog
public void WriteLog(ICorrelation correlation, LogEventLevel eventLevel, Exception exception, string formatMessage, params object[] args)
{
if (log == null)
{
log = loggerRepository.GetLogger(sourceType);
}
if (eventLevel == LogEventLevel.Verbose && !log.IsDebugEnabled)
{
return;
}
if (args != null && args.Length != 0)
{
formatMessage = string.Format(formatMessage, args);
}
log4net.Core.ILogger logger = log.Logger;
LoggingEvent logEvent = new LoggingEvent(sourceType, logger.Repository, logger.Name, MapEventLevel(eventLevel), formatMessage, exception);
if (correlation != null)
{
logEvent.Properties["CallerId"] = correlation.CallerId;
logEvent.Properties["CorrelationId"] = correlation.CorrelationId;
}
logger.Log(logEvent);
}
示例2: UnmarshallException
public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
{
ErrorResponse errorResponse = ErrorResponseUnmarshaller.GetInstance().Unmarshall(context);
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidParameterValue"))
{
return new InvalidParameterValueException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidParameterCombination"))
{
return new InvalidParameterCombinationException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidCacheParameterGroupState"))
{
return new InvalidCacheParameterGroupStateException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("CacheParameterGroupNotFound"))
{
return new CacheParameterGroupNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
return new AmazonElastiCacheException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
开发者ID:pbutlerm,项目名称:dataservices-sdk-dotnet,代码行数:26,代码来源:DeleteCacheParameterGroupResponseUnmarshaller.cs
示例3: ConstructorWithMessageAndInnerExceptionWorks
public void ConstructorWithMessageAndInnerExceptionWorks() {
var inner = new Exception("a");
var ex = new FormatException("The message", inner);
Assert.IsTrue((object)ex is FormatException, "is FormatException");
Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
Assert.AreEqual(ex.Message, "The message");
}
示例4: Log4NetLogger_LoggingTest
public void Log4NetLogger_LoggingTest()
{
string message = "Error Message";
Exception ex = new Exception();
string messageFormat = "Message Format: message: {0}, exception: {1}";
ILog log = new Log4NetLogger(GetType());
Assert.IsNotNull(log);
log.Debug(message);
log.Debug(message, ex);
log.DebugFormat(messageFormat, message, ex.Message);
log.Error(message);
log.Error(message, ex);
log.ErrorFormat(messageFormat, message, ex.Message);
log.Fatal(message);
log.Fatal(message, ex);
log.FatalFormat(messageFormat, message, ex.Message);
log.Info(message);
log.Info(message, ex);
log.InfoFormat(messageFormat, message, ex.Message);
log.Warn(message);
log.Warn(message, ex);
log.WarnFormat(messageFormat, message, ex.Message);
}
示例5: Initialize
/// <summary>
/// Initialize the form
/// </summary>
public void Initialize(List<Oid> selectedOids)
{
mSelectedOids = selectedOids;
// If no instances selected, inform and exit
if (mSelectedOids == null || mSelectedOids.Count == 0)
{
string lMessageError = CultureManager.TranslateString(LanguageConstantKeys.L_NO_SELECTION, LanguageConstantValues.L_NO_SELECTION);
Exception lException = new Exception(lMessageError, null);
ScenarioManager.LaunchErrorScenario(lException);
return;
}
cmbBoxSelectTemplate.SelectedIndexChanged += new EventHandler(HandlecmbBoxSelectTemplate_SelectedIndexChanged);
// Load the templates from configuration file and fill the Combo
LoadReportTemplates();
// Show the number of selected instances in the Title.
Text = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_ELEMENTSELECTED, LanguageConstantValues.L_ELEMENTSELECTED, mSelectedOids.Count);
// Set the default printer
lblNameOfPrint.Text = printDlg.PrinterSettings.PrinterName;
ShowDialog();
}
示例6: LinkedINHttpResponseException
/// <summary>
/// Constructs an <see cref="LinkedINHttpResponseException"/>.
/// </summary>
/// <param name="expectedStatusCode">The expected <see cref="HttpStatusCode"/> of the response.</param>
/// <param name="actualStatusCode">The actual <see cref="HttpStatusCode"/> of the response.</param>
/// <param name="message">The message descriving the cause of this exception.</param>
/// <param name="inner">The inner <see cref="Exception"/>.</param>
public LinkedINHttpResponseException( HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, string message, Exception inner )
: base(message, inner)
{
// set values
ExpectedStatusCode = expectedStatusCode;
ActualStatusCode = actualStatusCode;
}
示例7: ResponseShim
internal ResponseShim(IRestResponse resp,
IRequestShim req,
string baseUrl,
Exception error)
{
this.Request = req;
if (resp != null)
{
this.Code = resp.StatusCode;
this.Message = resp.StatusDescription;
//this.Content = Convert.ToBase64String(resp.RawBytes);
this.Content = UTF8Encoding.UTF8.GetString(
resp.RawBytes, 0, resp.RawBytes.Length);
this.IsSuccess = resp.IsSuccess;
}
this.BaseUrl = baseUrl;
this.Error = error;
var restErr = error as RestServiceException;
if (restErr != null)
{
this.Code = restErr.Code;
this.Message = restErr.Message;
}
}
示例8: UnmarshallException
public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
{
ErrorResponse errorResponse = ErrorResponseUnmarshaller.GetInstance().Unmarshall(context);
if (errorResponse.Code != null && errorResponse.Code.Equals("ListenerNotFound"))
{
return new ListenerNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("CertificateNotFound"))
{
return new CertificateNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("LoadBalancerNotFound"))
{
return new LoadBalancerNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidConfigurationRequest"))
{
return new InvalidConfigurationRequestException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
return new AmazonElasticLoadBalancingException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
开发者ID:nburn42,项目名称:aws-sdk-for-net,代码行数:26,代码来源:SetLoadBalancerListenerSSLCertificateResponseUnmarshaller.cs
示例9: CalculateGeometricSum
public static double CalculateGeometricSum(double ratio, double firstTerm, int seriesLength, int startTermNumber)
{
double sum = 0;
seriesLength++;
int nLength = seriesLength - startTermNumber;
if(ratio == 1)
{
Exception ratiois1 = new Exception("The ratio is not allowed to equal 1");
throw ratiois1;
}
if(startTermNumber > 1)
{
seriesLength--;
nLength = seriesLength;
sum = firstTerm * ((1 - Math.Pow(ratio, nLength)) / (1 - ratio));
nLength = startTermNumber;
sum -= firstTerm * ((1 - Math.Pow(ratio, nLength)) / (1 - ratio));
return sum;
}
sum = firstTerm * ((1 - Math.Pow(ratio, nLength)) / (1 - ratio));
return sum;
}
示例10: HandleConnectionError
public void HandleConnectionError(Exception exception, PluginProfileErrorCollection errors)
{
_log.GetLogger("Mercurial").Warn("Check connection failed", exception);
exception = exception.InnerException ?? exception;
const string uriFieldName = "Uri";
if (exception is MercurialExecutionException)
{
errors.Add(new PluginProfileError { FieldName = "Login", Message = ExtractValidErrorMessage(exception)});
errors.Add(new PluginProfileError { FieldName = "Password", Message = ExtractValidErrorMessage(exception) });
errors.Add(new PluginProfileError { FieldName = uriFieldName, Message = ExtractValidErrorMessage(exception) });
return;
}
if (exception is ArgumentNullException || exception is DirectoryNotFoundException)
{
errors.Add(new PluginProfileError{ FieldName = uriFieldName, Message = INVALID_URI_OR_INSUFFICIENT_ACCESS_RIGHTS_ERROR_MESSAGE });
}
if (exception is MercurialMissingException)
{
errors.Add(new PluginProfileError { Message = MERCURIAL_IS_NOT_INSTALLED_ERROR_MESSAGE });
}
var fieldName = string.Empty;
if (exception is InvalidRevisionException)
{
fieldName = "Revision";
}
errors.Add(new PluginProfileError {FieldName = fieldName, Message = exception.Message});
}
开发者ID:TargetProcess,项目名称:Target-Process-Plugins,代码行数:31,代码来源:MercurialCheckConnectionErrorResolver.cs
示例11: UnmarshallException
public override AmazonServiceException UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
{
ErrorResponse errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context);
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidParameterException"))
{
return new InvalidParameterException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("LimitExceededException"))
{
return new LimitExceededException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("OperationAbortedException"))
{
return new OperationAbortedException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("ResourceAlreadyExistsException"))
{
return new ResourceAlreadyExistsException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("ServiceUnavailableException"))
{
return new ServiceUnavailableException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
return new AmazonCloudWatchLogsException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
示例12: PromoteException
//Can only be called inside a service
public static void PromoteException(Exception error,MessageVersion version,ref Message fault)
{
StackFrame frame = new StackFrame(1);
Type serviceType = frame.GetMethod().ReflectedType;
PromoteException(serviceType,error,version,ref fault);
}
示例13: SendByMail
/// <summary>
/// Sends an error message by opening the user's mail client.
/// </summary>
/// <param name="recipient"></param>
/// <param name="subject"></param>
/// <param name="ex"></param>
/// <param name="assembly">The assembly where the error originated. This will
/// be used to extract version information.</param>
public static void SendByMail(string recipient, string subject, Exception ex,
Assembly assembly, StringDictionary additionalInfo)
{
string attributes = GetAttributes(additionalInfo);
StringBuilder msg = new StringBuilder();
msg.AppendLine("[ Please send this as plain text to allow automatic pre-processing ]");
msg.AppendLine();
msg.AppendLine(GetMessage(ex));
msg.AppendLine();
msg.AppendLine(GetAttributes(additionalInfo));
msg.AppendLine();
msg.AppendLine("[ Please send this as plain text to allow automatic pre-processing ]");
msg.AppendLine();
string command = string.Format("mailto:{0}?subject={1}&body={2}",
recipient,
Uri.EscapeDataString(subject),
Uri.EscapeDataString(msg.ToString()));
Debug.WriteLine(command);
Process p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.UseShellExecute = true;
p.Start();
}
示例14: SyncWebBrowserError
public void SyncWebBrowserError(Exception ex)
{
InvokeOnMainThread(() => {
UIAlertView alertView = new UIAlertView("Sync Web Browser Error", ex.Message, null, "OK", null);
alertView.Show();
});
}
示例15: ReportError
protected void ReportError(Exception e)
{
if (Errored != null)
{
Errored(this, new ErrorEventArgs(e));
}
}