I’m interested in handling only certain exceptions in my method, so I’ve went ahead and added the following filter:
catch( Exception ex ) when( ex.InnerException is SqlException {Number: 2601} ) {
// code removed
Unfortunately, it seems like this doesn’t always work, so I had to change the previous snippet to something like this:
When I say that it doesn’t always work, what I mean is that it’s called from several places (e.g. rest web service, windows 32 service) and it doesn’t work for all of them.
I did add a breakpoint to the when
clause, but it simply didn’t stop there. Since I had a catch all exception block in the parent method, I was able to run this check:
To me, it seems like the filter should catch the exception…
catch( Exception ex ) {
if( ex.InnerException is not SqlException {Number: 2601} ) { // shouldn't need this...
throw;
}
Does anyone know why the latest works and the 1st doesn’t? If I’m not mistaken, option 1 should be the way to go…am I missing something?
13