Eval() and Try/Catch: getting error line number

I need the number of the line where the error occurs within an eval(). When I don’t add any error handling, I get a message like

ReferenceError: "intentionallyError" is not defined. (C:\theWholePath\theJsFile.js#14(eval)#2)

The #2 is the line number within the eval() source-code where the error occurred, so this is exactly what I need! But when I add a Try/Catch block like

	try
	{
		eval(servoymethod);
	}
	catch(e)
	{
		application.output(e);
	}

I don’t get the line number anymore, how can I get it?

Hi!

marcelb:
I need the number of the line where the error occurs within an eval(). When I don’t add any error handling, I get a message like

ReferenceError: "intentionallyError" is not defined. (C:\theWholePath\theJsFile.js#14(eval)#2)

The #2 is the line number within the eval() source-code where the error occurred, so this is exactly what I need! But when I add a Try/Catch block like

	try
{
	eval(servoymethod);
}
catch(e)
{
	application.output(e);
}


I don't get the line number anymore, how can I get it?

Try to do something like this:

	try
	{
		eval(servoymethod);
	}
	catch(e)
	{
               application.output(e.rhinoException.getMessage())
	}

I hope this helps!

Or try to avoid using eval (eval is evil some people say):

var _form_name
var _method_name
var _m = servoymethod.match(/^globals\.(.*)$/)
if (_m) { // global method
	_method_name = _m[1]
	if (globals[_method_name) { // if method to call exists
		globals[_method_name]()
	}
}
else { // form method
	_m = servoymethod.match(/^forms\.(.*)\.(.*)$/)
	if (_m) {
		_form_name = _m[1]
		_method_name = _m[2]
		if (forms[_form_name][_method_name]) { // if method to call exists
			forms[_form_name][_method_name]()
`		}
	}
}

Yes, thanks Gerardo that does the trick, now I can parse the line number.

To Michel: I agree with you that Eval() is Evil but I get the source-code from the db and I need to create those methods with the solutionModel then and I think it is risky business in both calling-methods?