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
Edit:
here is what i currently get:
alt text http://img163.imageshack.us/img163/4503/83077881.png
If you look at the stack trace, which is displayed as part of the exception details, you should see the exact location of the exception, no matter how you format the code.
I guess that formatting the code differently would be useful if the debugger allowed you to put a breakpoint on a specific line, but in C#, breakpoints are placed on individual expressions, so this won’t really help. You’d probably need to rewrite the code like this to allow placing breakpoints:
The same applies to highlighting of the current expression (in your screenshot). However, the exact information about the exception are always available in the stack trace.