C# 6 exception filters and how they are much more than syntactic sugar
1–10 of 20 posts
Re: C# 6 exception filters and how they are much more than syntactic sugar
#2Re: C# 6 exception filters and how they are much more than syntactic sugar
#3I believe this will be more effiencient than an excess of concurrent filters.
Re: C# 6 exception filters and how they are much more than syntactic sugar
#4as I see it they aren't much more than "more syntactic sugar"
Syntactic sugar would be something like automatic property getters and setters in C#; they just shorten the syntax drastically and the compiler or runtime unroll your code to the traditional implementation.
In this case you can interrogate things normally bound up into the exception instance itself, like the message without having to hit the catch block to wait for it to be hydrated. Once you enter that catch block things happen in the runtime that are costly so avoiding that if possible is the best route.
Re: C# 6 exception filters and how they are much more than syntactic sugar
#5Re: C# 6 exception filters and how they are much more than syntactic sugar
#6as I see it they aren't much more than "more syntactic sugar"
Re: C# 6 exception filters and how they are much more than syntactic sugar
#7as I see it they aren't much more than "more syntactic sugar"
Exception filters are a CLR feature that modify this process a little. Now, when an exception is thrown, it still walks the stack looking for candidate catch blocks, but whenever it identifies a candidate, it will call the exception filter function (a function from exn -> bool, where exn is the exception being caught by the Catch block). If the function returns false, the CLR will disregard this candidate catch block and continue searching. C# 6.0 merely added some syntax that exposed this functionality of the CLR, the language itself isn't doing this.
Re: C# 6 exception filters and how they are much more than syntactic sugar
#8It looks really weird to me, having that empty catch block. I expect a lot of issues to accidentally be introduced from poor merges or something.
Re: C# 6 exception filters and how they are much more than syntactic sugar
#9It looks really weird to me, having that empty catch block. I expect a lot of issues to accidentally be introduced from poor merges or something.
I don't understand. Why would you have an empty catch block? He does in his example but that's an example. I cannot see why you'd even write a catch block if it was empty in production code (unless you're trying to do some error-and-continue pattern, which is rare/mostly an anti-pattern).
edit: to further clarify my objective, I was thinking of a way to make the stack traces better, without risking the maintainability of the code now that I'm aware of the difference. I guess in all it would be best to just remove it. In my case, we've found some strange things in unexpected places and I prefer to not change stuff, unless I understand how the underlying portions work.
Re: C# 6 exception filters and how they are much more than syntactic sugar
#10It looks really weird to me, having that empty catch block. I expect a lot of issues to accidentally be introduced from poor merges or something.
I don't understand. Why would you have an empty catch block? He does in his example but that's an example. I cannot see why you'd even write a catch block if it was empty in production code (unless you're trying to do some error-and-continue pattern, which is rare/mostly an anti-pattern).
An easy example are checking if a file exists under Windows 8, it's partly a product of the currently deficient API's but the fastest way to check if a file exists is to try to get it and catch the exception, and you'd want to return bool from a FileExists method