本文整理汇总了C#中Exception类的典型用法代码示例。如果您正苦于以下问题:C# Exception类的具体用法?C# Exception怎么用?C# Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Exception类属于命名空间,在下文中一共展示了Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPageCompletedEventArgs
/// <summary>
/// Constructor.
/// </summary>
/// <param name="page">The DocumentPage object for the requesed Page.</param>
/// <param name="pageNumber">The page number of the returned page.</param>
/// <param name="error">Error occurred during an asynchronous operation.</param>
/// <param name="cancelled">Whether an asynchronous operation has been cancelled.</param>
/// <param name="userState">Unique identifier for the asynchronous task.</param>
public GetPageCompletedEventArgs(DocumentPage page, int pageNumber, Exception error, bool cancelled, object userState)
:
base(error, cancelled, userState)
{
_page = page;
_pageNumber = pageNumber;
}
示例2: GridViewUpdatedEventArgs
public GridViewUpdatedEventArgs (int affectedRows, Exception e)
{
this.rowsAffected = affectedRows;
this.e = e;
this.exceptionHandled = false;
this.keepEditMode = false;
}
示例3: LogException
public static void LogException(string message, Exception ex)
{
var logger = log4net.LogManager.GetLogger(LOGGER_NAME);
if (logger == null)
return;
logger.Error(message, ex);
}
示例4: ThrowAsync
/// <summary>Throws the exception on the thread pool.</summary>
/// <param name="exception">The exception to propagate.</param>
/// <param name="targetContext">
/// The target context on which to propagate the exception; otherwise, <see langword="null"/> to use the thread
/// pool.
/// </param>
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
if (targetContext != null)
{
try
{
targetContext.Post(
state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
return;
}
catch (Exception ex)
{
exception = new AggregateException(exception, ex);
}
}
#if NET45PLUS
Task.Run(() =>
{
throw PrepareExceptionForRethrow(exception);
});
#else
ThreadPool.QueueUserWorkItem(state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
#endif
}
示例5: GetPageNumberCompletedEventArgs
/// <summary>
/// Constructor.
/// </summary>
/// <param name="contentPosition">The parameter passed into the GetPageNumberAsync call.</param>
/// <param name="pageNumber">The first page number on which the element appears.</param>
/// <param name="error">Error occurred during an asynchronous operation.</param>
/// <param name="cancelled">Whether an asynchronous operation has been cancelled.</param>
/// <param name="userState">Unique identifier for the asynchronous task.</param>
public GetPageNumberCompletedEventArgs(ContentPosition contentPosition, int pageNumber, Exception error, bool cancelled, object userState)
:
base(error, cancelled, userState)
{
_contentPosition = contentPosition;
_pageNumber = pageNumber;
}
示例6: JsonException
internal JsonException (ParserToken token,
Exception inner_exception) :
base (String.Format (
"Invalid token '{0}' in input string", token),
inner_exception)
{
}
示例7: LogExceptionsBulkUpload
public static void LogExceptionsBulkUpload(Exception Ex, string Page, string method)
{
string _SchLogs = System.Configuration.ConfigurationSettings.AppSettings["ServiceLogFolder"].ToString() + "Bulk_Exceptions.txt";
StringBuilder _BuilderException = new StringBuilder();
_BuilderException.Append("***********************************" + DateTime.Now.ToString() + "***********************************");
_BuilderException.AppendLine();
_BuilderException.Append(Ex.Message.ToString());
_BuilderException.AppendLine();
_BuilderException.AppendLine();
//page
_BuilderException.Append("Page :" + Page);
_BuilderException.AppendLine();
_BuilderException.AppendLine();
//mehotd
_BuilderException.Append("Method :" + method);
_BuilderException.AppendLine();
if (Ex.InnerException != null)
{
_BuilderException.AppendLine();
_BuilderException.Append(Ex.InnerException.ToString());
_BuilderException.AppendLine();
_BuilderException.Append(Ex.Message.ToString());
_BuilderException.AppendLine();
}
_BuilderException.Append("*****************************************************************************************************");
StreamWriter _Sche_Log = new StreamWriter(_SchLogs, true, Encoding.Default);
_Sche_Log.WriteLine(_BuilderException);
_Sche_Log.Close();
}
示例8: ExceltoDataView
public DataView ExceltoDataView(string strFilePath)
{
DataView dv;
try
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + strFilePath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'");
conn.Open();
object[] CSs0s0001 = new object[4];
CSs0s0001[3] = "TABLE";
DataTable tblSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, CSs0s0001);
string tableName = Convert.ToString(tblSchema.Rows[0]["TABLE_NAME"]);
if (tblSchema.Rows.Count > 1)
{
tableName = "sheet1$";
}
string sql_F = "SELECT * FROM [{0}]";
OleDbDataAdapter adp = new OleDbDataAdapter(string.Format(sql_F, tableName), conn);
DataSet ds = new DataSet();
adp.Fill(ds, "Excel");
dv = ds.Tables[0].DefaultView;
conn.Close();
}
catch (Exception)
{
Exception strEx = new Exception("請確認是否使用模板上傳(上傳的Excel中第一個工作表名稱是否為Sheet1)");
throw strEx;
}
return dv;
}
示例9: ParseFileException
public ParseFileException(string message, string fileName,
long? lineNumber, Exception causeException)
: base(message, causeException)
{
this.fileName = fileName;
this.lineNumber = lineNumber;
}
示例10: HandleException
private static void HandleException(Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ReadKey();
Environment.Exit(0);
}
示例11: ThrowWithData
public void ThrowWithData()
{
Exception e = new Exception(msg1);
e.Data[key1] = val1;
e.Data[key2] = val2;
throw (e);
}
示例12: GetNestedPropertyValue
/// <summary>
/// Retrieves the value of a property. That property can be nested.
/// Each element of the path needs to be a public instance property.
/// </summary>
/// <param name="item">Object that exposes the property</param>
/// <param name="propertyPath">Property path</param>
/// <param name="propertyType">Property type</param>
/// <param name="exception">Potential exception</param>
/// <returns>Property value</returns>
internal static object GetNestedPropertyValue(object item, string propertyPath, Type propertyType, out Exception exception)
{
exception = null;
// if the propertyPath is null or empty, use the
// item directly
if (String.IsNullOrEmpty(propertyPath))
{
return item;
}
string[] propertyNames = propertyPath.Split(PropertyNameSeparator);
for (int i = 0; i < propertyNames.Length; i++)
{
if (item == null)
{
break;
}
Type type = item.GetType();
// if we can't find the property or it is not of the correct type,
// treat it as a null value
PropertyInfo propertyInfo = type.GetProperty(propertyNames[i]);
if (propertyInfo == null)
{
break;
}
if (!propertyInfo.CanRead)
{
exception = new InvalidOperationException(string.Format(
System.Globalization.CultureInfo.InvariantCulture,
CommonResources.PropertyNotReadable,
propertyNames[i],
type.GetTypeName()));
break;
}
if (i == propertyNames.Length - 1)
{
// if the property type did not match, return null
if (propertyInfo.PropertyType != propertyType)
{
break;
}
else
{
return propertyInfo.GetValue(item, null);
}
}
else
{
item = propertyInfo.GetValue(item, null);
}
}
return null;
}
示例13: OnException
public void OnException(Exception e)
{
if (_errorCallback != null)
_errorCallback(e);
else
Debug.Log(e.Message);
}
示例14: DebugMessage
public void DebugMessage(Exception exception)
{
if (exception == null)
return;
DebugMessage(GetExceptionString(exception));
}
示例15: Abort
internal virtual void Abort(Exception e)
{
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("CommandStream" + LoggingHash.HashString(this) + "::Abort() - closing control Stream");
}
lock (this)
{
if (_aborted)
return;
_aborted = true;
}
try
{
base.Close(0);
}
finally
{
if (e != null)
{
InvokeRequestCallback(e);
}
else
{
InvokeRequestCallback(null);
}
}
}