?
Solved

Exception Line Numbers Riddle

Posted on 2010-11-21
16
Medium Priority
?
659 Views
Last Modified: 2012-05-10
I am attempting to debug a vb.net/ASP.NET application in VS2010.

When hitting F5 I get an exception on a seemingly innocuous line of code.  After playing around I've worked out that the exception is actually being thrown 5 lines before (and indeed looking at the stack trace this is confirmed).

Obviously this makes debugging pretty tricky - am I missing something obvious? I've tried to 'snip' all the evidence below!

 Screen shot showing line 425 throwing exception on bug in line 420
0
Comment
Question by:Ionican
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 34185970
Well... I think here your problem is pretty clear, you're using "field" array on your code without assigning it any value, this provokes the raise of the exception.

The reason why the exception is being misplaced is a mistery to me... maybe a bug on VS debugger?
0
 
LVL 9

Expert Comment

by:shadow77
ID: 34186035
Your field array is null when you try to store elements within it.

You need to add
    field = New String(ArgCount - 1) {}
after line 416.

Line 425 is the first line with executable code after line 420, which may be why your exception occurs there.
0
 

Author Comment

by:Ionican
ID: 34186037
Yes thanks Bardo - I spotted that one eventually (coffee helped).

But the odd 'offset' does worry me (and I've had this issue before) - makes me question the integrity of my dev environment (and the subsequent copying over to the staging server).

Has anyone else seen this before?
0
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
LVL 18

Accepted Solution

by:
Richard Lee earned 750 total points
ID: 34187334
I have had this issue once or twice before. Very frustrating that I can say. There are two things I tried when attempting to solve the problem.

1. Turn Optimization off.
http://msdn.microsoft.com/en-us/library/xz7ttk5s(VS.80).aspx
http://stackoverflow.com/questions/1199204/how-can-i-disable-compiler-optimization-in-c

In the IDE, project properties -> build -> "optimize code"

2. Turn break on Thrown exceptions on.
http://stackoverflow.com/questions/737514/where-is-the-debug-exceptions-window

DaTribe
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 34187338
BTW Select the THROWN checkboxes.

DaTribe
0
 

Author Comment

by:Ionican
ID: 34188047
Thanks DaTribe - that fixed it!  Not so lovely optimisations!
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 34188227
If my suggestion fixed it them  how come I don't get the points.

DaTribe
0
 

Author Comment

by:Ionican
ID: 34192522
Hi,

Bit confused here (apologies I'm an EE newbie) - but here goes:  

I played with the optimisations settings and tried to recreate my original issue (the issue being that the debugger was flagging up the exception in the wrong line) and it seemed that the optimisations flag did indeed correct the problem.  I was not able to roll back my code to recreate the exact original problem but it seems highly likely that DaTribe's contribution enabled me to eliminate the unpredictable debugger behaviour I was observing and which was the subject of this question.

To be clear: the question was not with the buggy code - that's reasonably straightforward (but thanks anyway to Shadow and Bardo) - it was that the debugger was sending me elsewhere to resolve the issue, hence the title of the question.

Hope that helps - Many thanks

0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 34195030
Yes this was my understanding of the entire scenario, however the question still remains - why not close the question and award no points instead of accepting my solution and awarding full points?

DaTribe
0
 

Author Comment

by:Ionican
ID: 34228122
Yes this makes sense as the appropriate outcome.

Thank you
0
 

Expert Comment

by:thermoduric
ID: 34265313
I am restarting the auto-close procedure on behalf of the question asker. After Moderator review, the new disposition seems to be more appropriate to the outcome of this question.

- thermoduric -
EE Community Support Moderator
http://www.experts-exchange.com/Q_26631209.html

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question