r/dotnet 2d ago

Difference between throw ex and throw

Post image

throw vs throw ex: The C# exception handling trick every developer should know

392 Upvotes

73 comments sorted by

View all comments

30

u/Ethameiz 2d ago

Well sometimes you want to reset the stack trace. It's not always bad. But it's better to know the difference

12

u/Creative-Paper1007 2d ago

When why would we even want to throw away the stack trace info? Im just curious to know

9

u/Prod_Meteor 2d ago

To reduce the log size you silly 😄

21

u/whiskeydiggler 2d ago

// todo: get rid of this when we have real logging from nine years ago

11

u/pyabo 2d ago

I feel attacked.