C# 为除任务取消之外的所有异常设置异常断点
我想在我的C#/Xamarin Studio项目中设置一个断点,该断点会中断所有异常,但与任务取消有关的异常除外。这可能吗?您应该为C# 为除任务取消之外的所有异常设置异常断点,c#,exception,breakpoints,xamarin-studio,C#,Exception,Breakpoints,Xamarin Studio,我想在我的C#/Xamarin Studio项目中设置一个断点,该断点会中断所有异常,但与任务取消有关的异常除外。这可能吗?您应该为取消异常使用单独的catch try { //do your stuff here } catch(CancellationException ex) { //behave cancellation } catch(Exception ex) { //Here handle other exceptions //Also you ca
取消异常使用单独的catch
try
{
//do your stuff here
}
catch(CancellationException ex)
{
//behave cancellation
}
catch(Exception ex)
{
//Here handle other exceptions
//Also you can put break point here
}
对于CancellationException
try
{
//do your stuff here
}
catch(CancellationException ex)
{
//behave cancellation
}
catch(Exception ex)
{
//Here handle other exceptions
//Also you can put break point here
}
如果您确切知道您的入口点,您可以编写如下代码:
try
{
....
}
catch (CancellationException)
{
throw;
}
catch (Exception ex)
{
//otherwise handle this exception
}
如果没有,则可以使用事件在应用程序域级别捕获
ApplicationDomain.UnhandledException。这里有更多详细信息:如果您确切知道您的入口点,您可以编写如下代码:
try
{
....
}
catch (CancellationException)
{
throw;
}
catch (Exception ex)
{
//otherwise handle this exception
}
如果没有,则可以使用事件在应用程序域级别捕获
ApplicationDomain.UnhandledException。这里有更多细节:我认为这是可能的。您可以添加捕获所有侦听System.Exception的异常。添加条件并检查异常类型,以跳过任务取消的异常。本地范围中的异常作为$Exception可用,因此条件如下!($exception是System.Threading.Tasks.TaskCanceledException)我认为这是可能的。您可以添加捕获所有侦听System.Exception的异常。添加条件并检查异常类型,以跳过任务取消的异常。本地范围中的异常作为$Exception可用,因此条件如下!($exception是System.Threading.Tasks.TaskCanceledException)您应该为取消异常使用单独的catch…我想在抛出时中断,因此捕捉没有帮助。因此,您可以使用在调试->异常中指定异常(VS2013)或者Debug
->Windows
->异常设置
(VS2015)您应该使用单独的捕获来取消异常…我想在抛出时中断,因此捕获没有帮助。因此,您可以使用在Debug
->异常
(VS2013)中指定异常或者Debug
->Windows
->异常设置
(VS2015)我需要在抛出时中断;关键是在调用堆栈展开之前中断。所以这没用。我需要在投掷时突破;关键是在调用堆栈展开之前中断。所以这没有帮助。谢谢你的回复。这方面的典型用例是,我想在抛出时中断,看看出了什么问题。但是我不想因为CancellationException而中断,因为这些并不是真正的错误。谢谢您的回复。这方面的典型用例是,我想在抛出时中断,看看出了什么问题。但我不想打断CancellationException,因为这些并不是真正的错误。