Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
davestewart
Topic Author
Posts: 114
Joined: Thu Mar 10, 2005 5:50 am
Location: London, UK
Contact:

try...catch

Mon Apr 11, 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!?)

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 Thu Apr 14, 2005 2:52 am, edited 1 time in total.
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Mon Apr 11, 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
Topic Author
Posts: 114
Joined: Thu Mar 10, 2005 5:50 am
Location: London, UK
Contact:

Tue Apr 12, 2005 6:47 am

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

Tue Apr 12, 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

{

   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
Topic Author
Posts: 114
Joined: Thu Mar 10, 2005 5:50 am
Location: London, UK
Contact:

Wed Apr 13, 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:
   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: Fri Mar 25, 2011 9:15 am
Contact:

Re: try...catch

Fri Aug 07, 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.

Who is online

Users browsing this forum: No registered users and 1 guest