C# 6 Exception Filters and How they are much more than Syntactic Sugar
-
Exception Filters are a new feature in C# 6 which allows you to specify conditions along with a catch block. The catch block is only executed if the condition satisfies.
catch(Exception ex) if (ex.Source="C#" && ex.Message.Contains("v.Next"))
-
Exception Filters are a new feature in C# 6 which allows you to specify conditions along with a catch block. The catch block is only executed if the condition satisfies.
catch(Exception ex) if (ex.Source="C#" && ex.Message.Contains("v.Next"))
Yaaaawn... We've had this for years in VB.NET! About time C# caught up! :D That's right VB haters! Better show some respect! For the record, I love C#, but VB.NET was my first love and I kind of have a weakness for it... And VB.NET doesn't deserve the hate it's getting (ok, some of it) :D
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
Yaaaawn... We've had this for years in VB.NET! About time C# caught up! :D That's right VB haters! Better show some respect! For the record, I love C#, but VB.NET was my first love and I kind of have a weakness for it... And VB.NET doesn't deserve the hate it's getting (ok, some of it) :D
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}I notice your signature contains C# code, not VB. BWAHAHAHAHA!!
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
I notice your signature contains C# code, not VB. BWAHAHAHAHA!!
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
Exception Filters are a new feature in C# 6 which allows you to specify conditions along with a catch block. The catch block is only executed if the condition satisfies.
catch(Exception ex) if (ex.Source="C#" && ex.Message.Contains("v.Next"))
I have a question, but I didn't want to sign-up at the site to ask it. I suppose this is a programming question, so I won't delve into it other than point out a flaw in the article. In the example he specifies a use case of logging without unwinding the stack. The premise sounds good except that at the point he logs he has no context for the exception. The most he can log is that there was an exception and maybe pass in some state information on a method overload. The exception object hasn't been created yet. I could be missing something. His original does the same thing -- there is no context to the exception.
-
If that's VB in your signature then I'm a monkey's uncle. :laugh: :laugh: :laugh: :laugh: :laugh:
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
If that's VB in your signature then I'm a monkey's uncle. :laugh: :laugh: :laugh: :laugh: :laugh:
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
That's not F# either. :rolleyes:
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
That's not F# either. :rolleyes:
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein -
I have a question, but I didn't want to sign-up at the site to ask it. I suppose this is a programming question, so I won't delve into it other than point out a flaw in the article. In the example he specifies a use case of logging without unwinding the stack. The premise sounds good except that at the point he logs he has no context for the exception. The most he can log is that there was an exception and maybe pass in some state information on a method overload. The exception object hasn't been created yet. I could be missing something. His original does the same thing -- there is no context to the exception.
The exception object has been created - it's just that the examples on that blog post don't show it. You could easily do:
try
{
...
}
catch (SomeException ex) if (Log(ex))
{
}This blog post[^] has a better example.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Keep guessing. When you get to C#, stop.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
I have a question, but I didn't want to sign-up at the site to ask it. I suppose this is a programming question, so I won't delve into it other than point out a flaw in the article. In the example he specifies a use case of logging without unwinding the stack. The premise sounds good except that at the point he logs he has no context for the exception. The most he can log is that there was an exception and maybe pass in some state information on a method overload. The exception object hasn't been created yet. I could be missing something. His original does the same thing -- there is no context to the exception.
Ummm...wrong. If the Exception hasn't been created yet, how is the catch block going to know about it? The Exception HAS been created by the time the catch block and the filters start executing. Ever set a breakpoint on a catch in VS? Without the catch executing, you get a little tag you can click and see the, wait for it, Exception object!
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Keep guessing. When you get to C#, stop.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Dude, with the tpye and quality of a lot of the questions that show up around here, I wouldn't doubt someone doesn't have a clue about what they put in their signature.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Dude, with the tpye and quality of a lot of the questions that show up around here, I wouldn't doubt someone doesn't have a clue about what they put in their signature.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Psshhhhht. Yeah, right. :-D
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak