question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make A<T>.Ignored throw an exception when it is invoked

See original GitHub issue

I know, that sounds crazy… but it’s not 😉

A<T>.Ignored (or its shortcut A<T>._) is used in call specifications to denote that any value of this argument should be a match. If you have long type names (e.g. IEnumerable<CustomerInvoiceDetailLine> or something like that), it can be tempting to do this:

var any = A<IEnumerable<CustomerInvoiceDetailLine>>.Ignored;
A.CallTo(() => x.PrintInvoiceDetails(any))....

However, this doesn’t work, because FIE analyzes the expression in A.CallTo to detect calls to A<T>.Ignored, and in this case the expression doesn’t contain it. A<T>.Ignored is not meant to actually be called, only to be analyzed as part of the call specification.

This can be very confusing to many users, so I think A<T>.Ignored should throw an exception (with a message explaining the problem) when it is invoked. It would be better to be able to detect it at compile time, but I don’t think it’s possible.

(this was inspired by this question about Moq, which has the same issue)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:29 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
blairconradcommented, May 31, 2016

@Jameskmonger, I was wrong. I thought my superseding PR (#619) was merged, but @thomaslevesque’s original PR (#611) was. The commit is 48dc7682e33a7e666b2ed7bebaf7325863313b75.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to invoke a method which throws an Exception using ...
InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor. http://docs.oracle.com/ ...
Read more >
How to Throw Exceptions in Java
Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception...
Read more >
An example of how suppressed exceptions in Java work
Don't ignore suppressed exceptions. In this quick tutorial we show you how to anticipate when code will throw suppressed exceptions, along with ...
Read more >
Ignore exception when closing a resource such as a file?
The reason, which as I recall Bloch explains, is that the interesting Exception is the original one thrown from within the try block....
Read more >
Manage exceptions with the debugger in Visual Studio
The debugger can break execution at the point where an exception is thrown, so you may examine the exception before a handler is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found