简体   繁体   中英

First-chance SocketException getting thrown but my catch isn't working

I have a WCF application that sometimes performs long running queries. I have created code on the client side that understands when a Timeout on the socket has occurred and will take steps to repoll the server later to grab the answer. The system throws a number of first-chance exceptions just before the TimeoutException occurs including SocketException. In the past, first-chance exceptions have slowed my apps considerably until I caught and handled them.

I want to get rid of these first-chance exceptions so I created a try-catch block to handle the SocketException and turned on the exceptions in VS2010 and reran the code. When I did, I saw the debugger show me that the SocketException had occurred, but my catch block was never entered. (see below)

在此输入图像描述

I found a number of similar posts including C# SocketException doesn't get caught but none of the answers I found address how to catch the Exception, or whether I should even worry about it.

So my questions are:

1) Should I be worrying about these first chance exceptions?

2) If so, how do I get the system to catch them?

There is an event you can attach to called AppDomain.FirstChanceException Event

this is how you would connect to it:

  AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;

it is on the app domain the application is running on here is the documentation on it. http://msdn.microsoft.com/en-us/library/system.appdomain.firstchanceexception.aspx

First chance exceptions are thrown exceptions that are already caught.

In other words, it is impossible to catch a first chance exception.

You also dont have to worry about them (generally).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM