Method chaining and exceptions in C#

Posted by devoured elysium on Stack Overflow See other posts from Stack Overflow or by devoured elysium
Published on 2010-05-21T15:01:18Z Indexed on 2010/05/21 15:10 UTC
Read the original article Hit count: 379

If I have a method chain like the following:

        var abc = new ABC();
        abc.method1()
           .method2()
           .methodThrowsException()
           .method3()
           ;

assuming I've defined method1(), method2() and method3() as

    public ABC method1() {
        return this;
    }

and methodThrowsException() as

    public ABC method3() {
        throw new ArgumentException();
    }

When running the code, is it possible to know which specific line of code has thrown the Exception, or will it just consider all the method chaining as just one line? I've done a simple test and it seems it considers them all as just one line but Method Chaining says

Putting methods on separate lines also makes debugging easier as error messages and debugger control is usually on a line by line basis.

Am I missing something, or does that just not apply to C#?

Thanks

© Stack Overflow or respective owner

Related posts about exception

Related posts about c#