The official Fatica Labs Blog! RSS 2.0
# Tuesday, 03 April 2012

I talked about this one file utility here and here. I decided the syntax I create in the last improvement, for allowing the user to customize the exception to throw was not so usable, so I modified it. Now the resulting code to throw a specific exception is:

        /// 
        /// Classical not null verification, with custom 
        /// exception and message
        /// 
        /// 
        public void DoSomethingWithCustomMessage(string arg1)
        {
            Contract.Expect(() => arg1)
                .Throw((n)=>new Exception(string.Format("I'm unhappy to see that {0} is null",n)))
                .WhenViolate
                .IsNotNull();
        }

 

So there is no more any magic formatting, we just need to provide a function returning some kind of exception. The lambda argument (n) is the literal representing the name argument. I also added a wiki page on the project repository, to show the basic usage of the library so at a glance you can see how it works.

Tuesday, 03 April 2012 07:55:51 (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
C#

All comments require the approval of the site owner before being displayed.
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, strike, strong) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
My Stack Overflow
Contacts

Send mail to the author(s) E-mail

Tags
profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Felice Pollano
Sign In
Statistics
Total Posts: 157
This Year: 0
This Month: 0
This Week: 0
Comments: 127
This blog visits
All Content © 2019, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano