Harshad Vaghela
Harshad Vaghela

Reputation: 37

How to find which line throws an exception in C#

How to know that which line throws an exception in c# code. I facing Selection Out of range exception directly on browser, so i can't detect where is the problem. I try debugging many times but can't find where is the problem. enter image description here Please help me to solving this.

Upvotes: 1

Views: 3134

Answers (2)

trailynx
trailynx

Reputation: 51

If you are using Visual Studio for debugging your server code, check the Exception Settings (if they are not visible go to the menu 'Debug' -> 'Windows -> 'Exception Settings' and they should appear in the lower right by default) and make sure that the debugger is set to break on the relevant exceptions - in your case I would check the 'Common Language Runtime Exceptions' tree, specifically the 'ArgumentOutOfRangeException' there (but I usually enable the whole tree).

With this setting enabled on your next debug session, the visual studio debugger should break where the exception is thrown and show you a popup with details.

Upvotes: 4

Rajesh
Rajesh

Reputation: 19

  • Have try catch for the whole code block.
  • Mark break point on catch.
  • So that you find from where it is throwing the exception.

Upvotes: 0

Related Questions