Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling in javascript

Status
Not open for further replies.

Belinar

Programmer
Joined
Feb 27, 2006
Messages
6
Location
US
Does anyone out there know how to get the line number an error or exception was generated on programatically? Thanks for the help if you can. :)

-Belinar
 
you can try double-clicking on your error message in the bottom left of your IE browser, or you can download FireFox and use it's built-in javascript console.

you can also download javascript debuggers for free which will perform the same as FireFox's debugger.



*cLFlaVA
----------------------------
spinning-dollar-sign.gif
headbang.gif
spinning-dollar-sign.gif

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I suggest you get Firefox and do a custom install. Choose the Developer Tools as well as the normal browser install. This installs the Web Developer Toolbar and gives single-click access to all manner of debugging goodies (including a decent javascript console).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thanks for the help, but i'm not using my JS in a web browser, and the debugger I have available isn't that great, which is why i wanted to generate the line number programatically.

Oh well. back to the drawing board.
 
It's a custom script engine for the company i'm working for.
 
I'd love to tell you but they don't like that. LOL
 
That really doesn't make much sense. How is this JavaScript being called if it's not from a browser?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
There are all kinds of scripting engines out there... this one uses javascript to acomplish the tasks it needs... the same way that LUA is used in World of Warcraft... there's no browser involved there either.
 
WSH uses Javascript, too, as JScript, and I use it in ASP all the time (my ASP language of choice).

Basically, the program that generates the error has to have the debugging tools built in to provide that kind of information. The best you can do is to write code to display values at different points, and narrow down where it's breaking down from that technique.

Lee
 
That's what i was afraid of... thanx though. :)
 
Some browsers do give you the line number in the error object passed to the "catch" call. For example, Firefox 1.5 gives me the line number for the error here:

Code:
<html>
<head>
<script type="text/javascript">
<!--

	try {
		// Your code here.
		// Any errors will be trapped. For example:
		nonExistentFuntionCall();   // <-- this should error
	}
	catch (errorDetail) {
		var s = '';
		for (props in errorDetail) s += 'errorDetail.' + props + ': ' + errorDetail[props] + '\n';
		alert(s);
		//alert('An error occurred. The problem was:\n\n' + errorDetail);
	}

//-->
</script>
</head>
<body>A page</body>
</html>

Maybe your JavaScript engine does too?

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The Siebel CRM software uses JavaScript also.
 
I believe that alert() is a method of the browser's window object, so wouldn't be available unless it was specifically implemented by another application.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top