I'm writing an app which for various reasons involves Internet Explorer (IE7, for the record), ActiveX controls, and a heroic amount of JavaScript, which is spread across multiple .js includes.
One of our remote testers is experiencing an error message and IE's error message says something to the effect of:
Line: 719
Char: 5
Error: Unspecified Error
Code: 0
URL: (the URL of the machine)
There's only one JavaScript file which has over 719 lines and line 719 is a blank line (in this case).
None of the HTML or other files involved in the project have 719 or more lines, but the resulting HTML (it's sort of a server-side-include thing), at least as IE shows from "View Source" does have 719 or more lines - but line 719 (in this case) is a closing table row tag (no JavaScript, in other words).
The results of "View Generated Source" is only 310 lines in this case.
I would imagine that it could possibly be that the entire page, with the contents of the JavaScript files represented inline with the rest of the HTML could be where the error is referring to but I don't know any good way to view what that would be,
So, given a JavaScript error from Internet Explorer where the line number is the only hint but the page is actually spread across multiple files?
UPDATE: The issue is exacerbated by the fact that the user experiencing this is remote and for various network reasons, debugging it using something like Visual Studio 2008 (which has awesome JavaScript debugging, by the way) is impossible. I'm limited to having one of us look at the source to try and figure out what line of code it's crapping out on.
UPDATE 2: The real answer (as accepted below) seems to be "no, not really". For what it's worth though, Robert J. Walker's bit about it being off by one did get me pointed in the right direction as I think it was the offending line. But since that's not really what I'd call good or reliable (IE's fault, not Robert J. Walker's fault) I'm going to accept the "no, not really" answer. I'm not sure if this is proper SO etiquette. Please let me know if it's not via the comments.
log() is a good way to debug errors but setting breakpoint is a faster, efficient and better method. In this method, Breakpoints are set in code which stops the execution of code at that point so that the values of variables can be examined at that time.
In short. Not really. Try finding the error in FF first, and if that fails, you can get an almost as good debugger with Visual Web Developer. Debugging IE just sucks for the most part.
The web developer toolbar in IE7 can give you a rendered source view.
View > Source > Dom (Page)
This might be more accurate when you consider the line numbers provided by IE for script errors.
The best way I found to debug javascript was to add several Response.Write() or alert message near the place i believed the code broke. The write or alert that doesn't show is closest to the problematic area of the code.
I did it this way because I haven't found an easier way.
Update: If you use this method of debugging you can use the writes/alerts to the contents of variables as well.
Tip: I find that many IE error message line numbers are off by one!
By installing firebug lite on your server for that page:
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'>
</script>
you can log to a virtual console with,
firebug.d.console.log("stuff and things")
firebug.d.console.dir( {returnedObject:["404", "Object Not Found"]} )
and ask your remote tester to get more details for you by pressing F12.
I sort of suspect there's an unterminated string or an unmatched parenthesis or bracket out there.
Nope, there isn't a way to make the built-in exception message suck less.
Instead you'll need to use a debugger with IE. The best tutorial I've found for this is here:
http://www.berniecode.com/blog/2007/03/08/how-to-debug-javascript-with-visual-web-developer-express/
Follow these instructions and when an error or exception occurs you will be shown the exact line in the correct file. You'll also see the value of variables in the current scope and you can setup "watched" items to help you debug.
Aside from that, if you need logging and CSS Cascade inspection like Firebug I've had good results with DebugBar and JSCompanion:
http://www.debugbar.com/ http://www.my-debugbar.com/wiki/CompanionJS/HomePage
Try Firebug. I is available for IE: http://getfirebug.com/lite.html
Have you checked whether this error is also present in Firefox using Firebug? That would be my first step in attempting to figure out where this error is occurring.
If it isn't present in Firefox, then I would progress to enabling script debugging in IE.
My only advice: don't use IE for debugging like this. It's the absolute worst of the mainstream browsers: I try to use Firefox (with Firebug) or Chrome/Safari to handle most issues.
If you absolutely have to use IE, install the IE Developer Toolbar (which doesn't seem to help much with JavaScript errors), and/or install the Script Debugger
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With