8 Replies Latest reply on Jan 7, 2013 3:03 PM by DawMatt

    Wrong error number being supplied to catch statement

    DawMatt Level 3

      Hi,

       

      I'm writing some JavaScript scripts for Photoshop Elements 11 and have struck a weird issue.

       

      Photoshop Elements 11's editor can run in Quick, Guided or Expert modes. Many operations (e.g. copying a layer) only work in Expert mode. So I'm trying to catch the error (8800) and let the user know they need to change modes and try the operation again. I'd prefer to activate the correct mode first and avoid the error altogether but that doesn't appear to be a scriptable feature.

       

      If I let the code run unprotected, it displays a dialog including the 8800 error number and a description of the problem. If I run the code in a basic try/catch (see below), the error number passed to the catch is is -25920. I've tried running the script directly in the PSE Editor and using the ExtendScript Toolkit's debug feature and the error number is the same every time.

       

      try {
          app.activeDocument.activeLayer.copy();
      }
      catch (e) {
          if (e.number == 8800) {
              alert("Correct error number");
          } else {
              alert("Error number is: " + e.number);
          };
      };
      
      

       

      Does anyone have any idea what could be happening here? I've looked through the scripting samples and xtools and my try/catch seems to be written correctly so I can't understand why the error number would get altered like this. Any ideas on how I can trap and respond to this error (and others) if the error number no longer matches up with the standard error numbers?

       

      Thanks,

      Matt

        • 1. Re: Wrong error number being supplied to catch statement
          c.pfaffenbichler Level 9

          This is the Photoshop Scripting Forum, Photoshop Elements is a different program.

          I doubt many of the contributors here have experience with Photoshop Elements.

          • 2. Re: Wrong error number being supplied to catch statement
            DawMatt Level 3

            Thanks for stopping by.

             

            c.pfaffenbichler wrote:

             

            This is the Photoshop Scripting Forum, Photoshop Elements is a different program.

            Correct. Unfortunately their isn't a Photoshop Elements Scripting forum so this is my best shot at having a worthy discussion about the topic.

             

            c.pfaffenbichler wrote:

             

            I doubt many of the contributors here have experience with Photoshop Elements.

            Fortunately Photoshop Elements knowledge shouldn't be necessary. Photoshop and Photoshop Elements use similar, if not the same, Javascript scripting engines. Both work with Extendscript Toolkit and can be set as scripting targets when debugging. ~97% of the Photoshop scripting objects and features are available in Photoshop Elements scripts, including some (e.g. opening images as Smart Objects) that most users wouldn't expect to see there. The main ones that aren't available are some higher end features (e.g. HDR) used to differentiate between the two programs. As my question is about try/catch error handling that should not be impacted by the ~3% difference between products.

             

            So how about you just pretend I didn't mention the "Elements" word. Have you heard of any instances when the wrong error number was included in an error object passed to a catch statement in a Photoshop javascript? Was there any way to convert it back to a usable error number to identify the error that should be responded to?

             

            Thanks,

            Matt

            • 3. Re: Wrong error number being supplied to catch statement
              c.pfaffenbichler Level 9

              Have you heard of any instances when the wrong error number was included in an error object passed to a catch statement in a Photoshop javascript?

              I can’t remember such an occurence, but others may have more insight on this.

               

              Can you check for the mode at all?

              • 4. Re: Wrong error number being supplied to catch statement
                DawMatt Level 3

                c.pfaffenbichler wrote:

                 

                Can you check for the mode at all?

                Not directly.

                 

                At the moment the best I can do is wrap the active layer copy line in its own try/catch, and pop up an alert explaining they are in the wrong mode and to please change it and try again. For another one of these scripts this will be the only reason I'm doing a layer copy at all.  Inelegant but better than nothing.

                • 5. Re: Wrong error number being supplied to catch statement
                  c.pfaffenbichler Level 9

                  Not directly.

                  Do documents on PSE have no descriptor for that property?

                  • 6. Re: Wrong error number being supplied to catch statement
                    DawMatt Level 3

                    c.pfaffenbichler wrote:

                    Not directly.

                    Do documents on PSE have no descriptor for that property?

                    This mode being tested for is a UI mode for the Photoshop Elements Editor, rather than a mode for the document itself. ScriptListener doesn't record any information when changing these Editor modes.

                    • 7. Re: Wrong error number being supplied to catch statement
                      c.pfaffenbichler Level 9

                      Just to make sure could you try the following code to see if the property is one of the listed ones?

                      This code works for Photoshop, hopefully it also works for PSE.

                       

                      // based on code by michael l hale;
                      // 2012, use it at your own risk;
                      #target photoshop
                      var ref = new ActionReference();
                      ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      //ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      var applicationDesc = executeActionGet(ref);
                      checkDesc2(applicationDesc);
                      ////// based on code by michael l hale //////
                      function checkDesc2 (theDesc) {
                      var c = theDesc.count;
                      var str = '';
                      for(var i=0;i<c;i++){ //enumerate descriptor's keys
                                str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
                                };
                      alert("desc\n\n"+str);
                      };
                      ////// check //////
                      function getValues (theDesc, theNumber) {
                      switch (theDesc.getType(theDesc.getKey(theNumber))) {
                      case DescValueType.BOOLEANTYPE:
                      return theDesc.getBoolean(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.CLASSTYPE:
                      return theDesc.getClass(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.DOUBLETYPE:
                      return theDesc.getDouble(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.ENUMERATEDTYPE:
                      return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
                      break;
                      case DescValueType.INTEGERTYPE:
                      return theDesc.getInteger(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.LISTTYPE:
                      return theDesc.getList(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.OBJECTTYPE:
                      return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
                      break;
                      case DescValueType.REFERENCETYPE:
                      return theDesc.getReference(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.STRINGTYPE:
                      return theDesc.getString(theDesc.getKey(theNumber));
                      break;
                      case DescValueType.UNITDOUBLE:
                      return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
                      break;
                      default: 
                      break;
                      };
                      };
                      
                      • 8. Re: Wrong error number being supplied to catch statement
                        DawMatt Level 3

                        Tried that script, but unfortunately executeActionGet() appears to be one of those features they disabled in Photoshop Elements. Looks like I'll just need to stick with my less than elegant solution for the moment.

                         

                        Thanks for your help with this issue!