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:

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: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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:

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

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:

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:

[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.
PhSn
Posts: 1
Joined: June 13th, 2008, 2:23 pm

Again 5 years later - 2020 - and we're still facing this problem with try and catch in AE ...

So here is the updated code for AE (CC) 2020

Code: Select all

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

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

Setting has moved from the regular Preferences file

Adobe After Effects $versionNumber.x Prefs.txt”

to the machine independent preferences

Adobe After Effects $versionNumber.x Prefs-indep-general.txt”

which is pointed out by the PREFType.PREF_Type_MACHINE_INDEPENDENT other files are

PREF_Type_MACHINE_SPECIFIC: Adobe After Effects $versionNumber.x Prefs.txt
PREF_Type_MACHINE_INDEPENDENT: Adobe After Effects $versionNumber.x Prefs-indep-general.txt
PREF_Type_MACHINE_INDEPENDENT_RENDER: Adobe After Effects $versionNumber.x Prefs-indep-render.txt
PREF_Type_MACHINE_INDEPENDENT_OUTPUT: Adobe After Effects $versionNumber.x Prefs-indep-output.txt
PREF_Type_MACHINE_INDEPENDENT_COMPOSITION: Adobe After Effects $versionNumber.x Prefs-indep-composition.txt
PREF_Type_MACHINE_SPECIFIC_TEXT: Adobe After Effects $versionNumber.x Prefs-text.txt
PREF_Type_MACHINE_SPECIFIC_PAINT: Adobe After Effects $versionNumber.x Prefs-paint.txt

(http://docs.aenhancers.com/other/settings/)

Post Reply