try...catch

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

April 11th, 2005, 8:56 am

Try/catch combinations still bring up the debugger in AE.

Obviously this could be useful from a development point of view, but what about production. Is there a way to disable the debugger from launching (apart from writing perfect code!?)

Code: Select all

function testTry(printErrors){
	try{
		unknownFunction(unknownVariable)
		}
	catch(err){
		var str=''
		for(i in err)str+=i+': '+err[i]+'\n'
		if(printErrors)alert(str)
		}
	}

testTry(true)
Cheers,
Dave
Last edited by davestewart on April 14th, 2005, 2:52 am, edited 1 time in total.
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

April 11th, 2005, 8:55 pm

The only thing I can think of is turning off the preference that enables the debugger. Kind of a pain though.

Dan
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

April 12th, 2005, 6:47 am

Yup... that's all I came up with as well.
Thanks anyway...
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

April 12th, 2005, 12:40 pm

I wrote this a while back to see if I could turn off the debugger from within a script if I was using try/catch. It seems to work ok.

Paul T

Code: Select all

{

	function isDebuggerOn()
	{
		var debuggerSetting = app.preferences.getPrefAsLong("Main Pref Section",
						"Pref_JAVASCRIPT_DEBUGGER");
		// returns true if debugger setting pref is 1
		return (debuggerSetting == 1);
	}


	function turnDebuggerOff()
	{
		app.preferences.savePrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER", 0)
	}


	function turnDebuggerOn()
	{
		app.preferences.savePrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER", 1)
	}


	// Main Script

	var wasDebuggerOn = isDebuggerOn()
	if (wasDebuggerOn == true) {
		turnDebuggerOff();
		alert("Debugger was turned on. Now prefs say, Debugger on = " + isDebuggerOn()); 
	}

	app.preferences.saveToDisk();
	app.preferences.reload();

	try { thisWillBreakIt;
	} catch(e) {
	}

	if (wasDebuggerOn == true) {
		turnDebuggerOn();
	}

	app.preferences.saveToDisk();
	app.preferences.reload();
}

davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

April 13th, 2005, 5:23 am

Great stuff, thanks Paul!

I checked the scripting guide and object model, but found no reference to an app.preferences or savePrefAsLong. They work great, but where did you get these from?

I simplified the code slightly too; thanks:

Code: Select all

	function getDebuggerState(){ 
		return Boolean(app.preferences.getPrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER"))
		}


	function setDebuggerState(state){ 
		app.preferences.savePrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER", Number(state)) 
		app.preferences.saveToDisk(); 
		app.preferences.reload(); 
		} 

	setDebuggerState(false) 

	try{thisWillBreakIt}
	catch(e){} 

	alert(getDebuggerState())
zold
Posts: 14
Joined: March 25th, 2011, 9:15 am
Contact:

August 7th, 2015, 5:09 pm

[EDIT][not that anyone is paying attention, but ...]
[[[
I haven't found a working solution to check or set the javascript debugger in v13.5(1) of AE CC. The "solution" I came up with below works great to seemingly switch the setting, then, after quitting AE, make AE fail to launch until changing EnableExpressionsDebuggingAtYourOwnRisk back to 0 by hand (or trashing preferences).
Looks like this is worth a sending a msg to Todd K....
]]]

Well, here we are, a decade later, and ...

Adobe has changed the preferences section name and key a couple of times, I think, since CS6.

According to my plodding and prodding, it seems that these debugger section names need to be checked:

For pre-CC: "Main Pref Section"
For CC pre-2015 (v13.5): "Main Pref Section v2"
for CC 2015 (v13.5): "Extendscript"

and the keys:
"Pref_JAVASCRIPT_DEBUGGER" (for first two)
"EnableExpressionsDebuggingAtYourOwnRisk" (for "Extendscript" section only)

I may be missing something, but I was able to get AE v13.5 to do the toggling of Script Debugger using the "Extendscript" section name and "EnableExpressionsDebuggingAtYourOwnRisk" key. I kind of missed out on what was and wasn't working during the CC pre-v13.5 era.

The try/catch error block has always been strangely implemented in AE, and this debugger preference behavior was considered a bug that basically never got fixed since it was first noticed and reported. So the workaround was created, and they broke that a couple of times, just for fun.

Just putting this in here to aid anyone who might stumble upon it.

If someone would like to chime in about why these things need to change at all, feel free. I think I know, though, considering how the CC model works, and the rather bad record of backwards compatibility that AE in particular has had.
Post Reply