Copy link to clipboard
Copied
I hope it's not inappropriate to ask about the ESTK here. I use it frequently to debug code, but one irritating facet occasionally trips me up.The ESTK frequently (but not all the time) doesn't respect the try/catch. It will stop on the line in the try and not process the code in the catch. This happens despite my having "Don’t Break On Guarded Exceptions" checked under the Debug menu.
Is this a known issue? Is there a workaround? When I create a test document, of course it works as it should. But in my actual code this isn't the case. Is there some setting I could be adjusting within the code without realizing it?
When it's just a matter of skipping over a line, it doesn't really matter (I can click Run and it will usually move on). But more frequently I need my catch to do something and debugging becomes very difficult without it.
xbytor2 just give me the solution:
When using ESTK debug, the try/catch will not throw error if I put level=0 before and then returning to level 1 after that:
$.level = 0;
try {
// some code ...
} catch (e) { }
$.level = 1;
Copy link to clipboard
Copied
I have the same problem using ESTK 4.0.0.1 and CC2014
Copy link to clipboard
Copied
Rather than using them as regular flow control, I leave exceptions to the exceptional circumstances that in any case require programmer attention. The typical check whether a collection has an item for a name is better tested via the isValid property.
Do you happen to have your code wrapped into an app.doScript in order to use undo modes? I remember having trouble with such constructs.
Dirk
Copy link to clipboard
Copied
For example, I use this to get annotations on an image document on photoshop.
Running from ESTK it breaks on try/catch
How could I use isValid() to prevent that?
function getAnnotationCount () {
var index = 0;
while (hideAnnotation (index)) {
index++;
}
return index;
// Dummy action, only used to test the existence of an annotation by index...
function hideAnnotation (index) {
var exists = true;
var desc = new ActionDescriptor ();
var ref = new ActionReference ();
ref.putIndex (stringIDToTypeID ('annotation'), index);
desc.putReference (stringIDToTypeID ('target'), ref);
try {
executeAction (stringIDToTypeID ('hide'), desc, DialogModes.NO);
} catch (e) { exists = false; }
return (exists);
}
}
Copy link to clipboard
Copied
Ah, I see what you mean with asking about ESTK in general - there is no class "Annotation" in the object model of my PS / CS6. As I mainly work with InDesign and only in rare cases with Illustrator, I am not used to the tricks required by other target applications e.g. due to lack of scripting support for native features.
Sorry,
Dirk
Copy link to clipboard
Copied
xbytor2 just give me the solution:
When using ESTK debug, the try/catch will not throw error if I put level=0 before and then returning to level 1 after that:
$.level = 0;
try {
// some code ...
} catch (e) { }
$.level = 1;
Copy link to clipboard
Copied
I'd love to be able to mark an answer here, but the Adobe forums have been
blocked off to me for days; I just get the dreaded redirect bug which is I
guess a standard feature now. Thanks for looking into this, folks, and if I
can ever log back in I'll happily mark this closed given the tip about
levels.
Copy link to clipboard
Copied
...another way to debug with try/catch is by checking Debug > Don’t Break On Guarded Exceptions in the ESTK
Find more inspiration, events, and resources on the new Adobe Community
Explore Now