Jump to content

discovering errors


ChrisGr

Recommended Posts

i am totaly new in javascript and i would like to find where the errors are in my code. is there a tool or some hints to help me?
i want to do this because i have embeded in my html and php code some javascript and it gives me two errors. as a result the page does not play as it should. IE points the errors but i cannot find them because the lines it gives are incorect and .... ??? iam new in this. Thank you in advance.
Link to comment
Share on other sites

Very good questions. In the few years I've been dealing with Javascript, I have not found an [i]easy[/i] way to debug. With PHP, your line numbers and all are actually printed to the screen, along with the actual errors, but as you say, with Javascript, IE [b]attempts[/b] to calculate the line number that it occurs on, but it is always in relationship to the actual rendered HTML, so if you're using PHP to generate your page, it can be nigh impossible to track down the precise location of the error that way.

The best tool by far that I have found is the Javascript console equipped within the [url=https://addons.mozilla.org/firefox/60/]Web Developer extension[/url] for firefox. This gives very nice, detailed descriptions that aren't nearly as cryptic as those from IE. In addition, once you've traced down the [b]location[/b] of your error, some well places javascript alert()s showing the values of variables in question can be invaluable to debugging your code.

I hope this helps some.
Link to comment
Share on other sites

  • 2 weeks later...
JS line numbers usually refer to the last line that it could process, which also means that unless it's one of those "null is null or not a object" errors, it's usually one line above.  But then with separete runtimes, you'll always get line 1. 
Link to comment
Share on other sites

  • 2 weeks later...
yeah, that might be...
But IE's default javascript validator screams error in the down left corner (!) without doing any good explanation about the real problem at all. So it is (almost) useless for the developer, and the average visitor don't know what that yellow warning means at all anyways. In my sense it a waste exept that when it's not there its assumed that whatever you made is working in IE.
It boils down to the fact that you need it just to check that your javascript is running ok in IE, but if it screams you cannot be sure to figure out where the problem is based on the information provided.
Link to comment
Share on other sites

[quote]the visitor should never see any JS errors ever[/quote]
True - still far from reality

[quote]and the developer should be smart enough to track down the errors without a complex validation plug-in[/quote]
I guess that can be claimed, but we all use different tools one way or the other. One can scratch head for 30 minutes just to find a simple but "invisible" typo or use tools to find it and fix it in less than one.
Link to comment
Share on other sites

[quote author=alpine link=topic=117567.msg491707#msg491707 date=1167139465]
[quote]the visitor should never see any JS errors ever[/quote]
True - still far from reality

[quote]and the developer should be smart enough to track down the errors without a complex validation plug-in[/quote]
I guess that can be claimed, but we all use different tools one way or the other. One can scratch head for 30 minutes just to find a simple but "invisible" typo or use tools to find it and fix it in less than one.

[/quote]

Supressing errors isn't hard to do in a production environment; and yes, tools make it very easy not to learn how to do anything.
Link to comment
Share on other sites

[quote author=fenway link=topic=117567.msg492187#msg492187 date=1167242952]
and yes, tools make it very easy not to learn how to do anything.
[/quote]
depends on what tools you use and how you use them. This became a silly and irrellevant discussion, we both know that!
As a crafts-man i know to appreciate the value of tools, that is the fact whatever proffession you are in.
Link to comment
Share on other sites

That's a silly thought anyhow!
If you stand with a modern car that wont start, what would you do ? Start checking each and every component manually and exchanging suspisious parts one by one until it eventually starts OR plug on the diagnostic reader to narrow down the problem or even find exactly what causes it?  If you are doing it as an amateur home in your own shed i would say that the first one is most often the case, but when you are doing it for a living OR have the instrument available and know how to use it - the instrument is the solution, anything else would be insane. But it still doesn't make you an idiot, and you still learn by pattern what's most commonly the fault on the different carbrands from the symtoms that you have previously experienced and fixed.

You have several degrees of using tools, the very one you have in front of you while reading this is a tool. Without it you would't be reding any of this...  you can make a fire to cook coffee or you can make it using the coffe machine instead - really is up to you. If your house goes totally dark you can start exchanging lightbulbs OR find the voltmeter (it's a tool) to see if you infact have power in your fusebox first - really is up to you. Where would the world be without tools ? We sure as hell wouldn't be sitting here typing.

By guessing, i figure you must be turning off all error reporting and notices while running php applications too ? Because that's the exact same thing as not using for instance the firebug extention for javascript. It's nothing but an error reporting and notice tool. You might call me and others using it for idiots, i don't.
Link to comment
Share on other sites

This argument/conversation/discussion is going down a slippery slope, so I'm going to quit before it gets ugly.  Suffice it to say that there's nothing wrong with using a diagnostics reader to figure out what wrong, provided that you know how each component works, and it's just a time saver.  99% of the time, looking at the code for another 10 seconds will reveal the problem outright.
Link to comment
Share on other sites

[quote author=alpine link=topic=117567.msg493966#msg493966 date=1167523773]
A good discussion is nothing but healthy, this one however emerged from its proposions. No hard feelings!
[/quote]
True enough... it's more a matter of personal preference.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.