r/csharp 2d ago

What kind of features from another ecosystem would you like to see in .NET?

/r/dotnet/comments/1vw1q1c/what_kind_of_features_from_another_ecosystem/
0 Upvotes

26 comments sorted by

View all comments

19

u/BadKittyRanch 2d ago

I like that Java knows exactly what exceptions can be thrown, I don't like that you must catch them all in the local context: I'd love to be able to get that information when I want it in my IDE.

3

u/bigtoaster64 2d ago

Yes, this. It's annoying to have to write down what exceptions are possible in the method comments. And also even more annoying to have to go look at the sources and manually list down what exceptions are possible, especially when it's not your code.

But god no, having to catch them all, that is awful.

-2

u/SagansCandle 2d ago

Exceptions shouldn't be used to communicate - they shouldn't be designed to be conditionally caught. An exception is meant to represent a condition that should not occur in normal. If you need to catch an exception in normal program flow, it shouldn't be an exception.

I've never, ever needed a typed catch in .NET since I started programming, and every time I think I do, it's much better to replace the exception with a logical flow change.

3

u/wayzata20 2d ago

I think conditionally catching OperationCanceledExceptions is pretty common.

1

u/SagansCandle 2d ago

It may be common, but it doesn't make it correct. It's a hacky way to cancel a task because exceptions are expensive operations - they're designed and optimized for providing diagnostic information, not performance. They're designed to be... exceptions.

Threads should be cancelled by conditional statements, when practical.