Get debugging (line/column) info for exceptions in try/catch

Hi!
Is there a way I can get debugging info, such as line and column, about a caught exception?
If it's left uncaught, DOpus tells me the info in output, but on first sight, the object that it provides to the catch block doesn't seem to contain any:

image

// ...
// ...
function OnClick(data)
{
	try{
		a = b + c;
	}
	catch(e){
		log(e);
	}
	a = b + c;
}

function log(obj) {
	obj = stringify(obj) + "";
	var l = obj.length;
	var c = l;
	var maxLen = 65520;
	while(c>maxLen){
		DOpus.Output(obj.substr(l-c, maxLen));
		c -= maxLen;
	}
	DOpus.Output(obj.substr(l-c));
}

function msg(s, buttons) {
	if(typeof(buttons) == "undefined")
		buttons = "OK";
	
	var dlg = DOpus.Dlg;
	
	var arr = buttons.split("|");
	if(arr.length>1){
		var defid = 1;
		for(var i = 0; i<arr.length; i++){
			var b = arr[i];
			if(b.substr(0,1)=="+"){
				defid = i+1;
				arr[i] = b.substr(1);
			}
		}
		dlg.defid = defid;
		buttons = arr.join("|");
	}
	s = stringify(s);
	log("MSG: " + s);
	dlg.message = s;
	dlg.buttons = buttons;
	dlg.icon = "info";
	return dlg.show();
}

function stringify(obj) {
	if(typeof obj == "undefined")
		obj = "[undefined]";
	else if(obj === null)
		obj = "[null]";
	else if(typeof obj == "object"){
		var o = obj;
		obj = "[Object " + DOpus.TypeOf(obj) + "]\n";
		obj += dump(o);
	} else if(obj === false)
		obj = "FALSE";
	else if(obj === true)
		obj = "TRUE";
	else if(obj==="")
		obj = "[empty]";
	return obj;
}

function dump(arr, level){
	var dumped_text = "";
	if(!level) level = 0;

	var bs = "\n";

	var level_padding = "";
	for(var j = 0; j < level + 1; j++) level_padding += "	 ";

	if(typeof (arr) == 'object'){ //Array/Hashes/Objects 
		for(var item in arr){
			var value = arr[item];

			if(typeof (value) == 'object'){
				dumped_text += level_padding + "'" + item + "' (" + DOpus.TypeOf(value) + "){" + bs;
				dumped_text += dump(value, level + 1) + bs + "}";
			}else{
				if(typeof(value.toString)=="function")
					value = value.toString();
				var m = value.match(/function\s*\(([^\)]*)\)\s*\{/i);
				if(m)
					value = "function(" + m[1] + ")";
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"" + bs;
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>" + arr + "<===(" + typeof (arr) + ")";
	}
	return dumped_text;
}```

Wow, trying to research JScript Error handling brings up nothing but disappointment :sweat_smile:
I thought Maybe I could find good examples of general implementations, or making use of ad-hoc created errors, re-throwing the original exception and printing something like a .stack property with it... but nope, looks like we're SOL o.o

Microsoft really didn't care too much about in-script debugging when they came up with their JScript paradigm, eh?

Can I ask the team, if there is a feasible way, to use a preprocessor to replace any error handling and pipe in the debugging info that the executing script or engine has?
That would be neat :slight_smile:
And also: While you're using a preprocessor to include debugging info: It would be sweet to include position info within eval calls: You could slap the evaluation in a wrapper that keeps track of added line numbers, or, for static values, unroll the whole evaluation into the intermediate (processed) script.
That would give users the opportunity to adjust the line numbers to report by subtracting the line number at which a (string?) value was eval'd where ever necessary, and know at which line in the eval'd string the problem was

:grin: A boy can dream, right? :slight_smile: