Here is another basic question.
If I have something like this
Code: Select all try {
var test = app.activeDocument[0];
} catch (e) {
alert(e.number)
err=e
alert(err.number)
alert(err.description)
}
and set a breakpoint at the second alert I can see in the data browser that err has the following properties start, source, number, message, line, file name, and end.
I thought that would be all of the properties for err. Why doesn't the third alert display 'undefined'?
Is there another way to fine the properties and/or methods of an object other than the data browset?
Thanks,
Mike
The Error Object
The Error Object
That's interesting while I can get your alerts to work when I run the script from PS, I cannot make it work in the estk. Also, in the estk while it gives me err as an object it does not give me any properties for the object.
Anyway, I have been wanting to be able to pull the line number from an error for a long time, I've posted about it more than once and never an answer. Now I know how.
Code: Select alltest();
function test() {
try {
test = v.s;
}
catch (e) {
for (var p in e) {
alert(p + '' + e[p]);
}
}
}
Andrew
Anyway, I have been wanting to be able to pull the line number from an error for a long time, I've posted about it more than once and never an answer. Now I know how.
Code: Select alltest();
function test() {
try {
test = v.s;
}
catch (e) {
for (var p in e) {
alert(p + '' + e[p]);
}
}
}
Andrew
The Error Object
There is more than one type of error and not all are objects.
I've done some more work on this, testing with the following code:
Code: Select alltest();
function test() {
try {
var a = [];
a.length = -1;
}
catch (e) {
var str = 'typeof e: ' + typeof e + '\n\nContents of e: ' + e + '\n\n';
if (typeof e == 'object') {
for (var p in e) {
if (p == 'fileName' || p == 'source') continue;
str += p + ': ' + e[p] + '\n\n';
}
}
alert(str);
}
}
The Object errors include: Type Error, Range Error and Reference Error.
A Type Error can be generated with:
Code: Select allvar a = null;
var b = a.b;
A Range Error can be generated with:
Code: Select allvar a = [];
a.length = -1;
A Reference Error can be generated by calling a variable that does not exist eg alert(idonotexist);
When you use throw('my throw text') 'e' is a string not an object
In addition:
The error type Syntax Error is reported directly in an error alert and does not get passed on to a catch clause - UNLESS it arises as part of an eval statement in which case it does get passed to the catch as an object.
Javascript has two other error types,
EvalError - which I was unable to force, and
URIError Object which probably has no relevance to ExtendScript.
Andrew
I've done some more work on this, testing with the following code:
Code: Select alltest();
function test() {
try {
var a = [];
a.length = -1;
}
catch (e) {
var str = 'typeof e: ' + typeof e + '\n\nContents of e: ' + e + '\n\n';
if (typeof e == 'object') {
for (var p in e) {
if (p == 'fileName' || p == 'source') continue;
str += p + ': ' + e[p] + '\n\n';
}
}
alert(str);
}
}
The Object errors include: Type Error, Range Error and Reference Error.
A Type Error can be generated with:
Code: Select allvar a = null;
var b = a.b;
A Range Error can be generated with:
Code: Select allvar a = [];
a.length = -1;
A Reference Error can be generated by calling a variable that does not exist eg alert(idonotexist);
When you use throw('my throw text') 'e' is a string not an object
In addition:
The error type Syntax Error is reported directly in an error alert and does not get passed on to a catch clause - UNLESS it arises as part of an eval statement in which case it does get passed to the catch as an object.
Javascript has two other error types,
EvalError - which I was unable to force, and
URIError Object which probably has no relevance to ExtendScript.
Andrew
The Error Object
Andrew wrote:That's interesting while I can get your alerts to work when I run the script from PS, I cannot make it work in the estk. Also, in the estk while it gives me err as an object it does not give me any properties for the object.
Your post about ESTK in this thread bb/viewtopic.php?t=439 strated the trail of posts I used to find this. It's not my idea, it comes from a post by Robert Strucky that is no longer on the Abode site.
Which leads me to ask if you updated your ESTK? I only tried it in ESTK. In the data browset there is a triangle icon next to err. If you click on that icon it drops down to show the properties. But description is not in that list is ESTK, which is why I posted my question about why it's not undefined. At the time I thought it wasn't a property. I found it a while back while doing a blind search for a property that I could use to match instead of the error string.
There is more than one type of error and not all are objects.
Yes, and it seems that all of the General Photoshop error type error have the same error number. Still it might be helpful to note the type of error if you are logging them.
I think that you are only using the error mechanism when you use throw without a real error so it throws what ever you give it.
Code: Select allvar stop = true;
try{
if (stop) var obj = new Object ; throw obj
}catch(e){
alert(typeof e); //object
}
I'm still looking for a way to handle General errors without using strings
Mikr
Your post about ESTK in this thread bb/viewtopic.php?t=439 strated the trail of posts I used to find this. It's not my idea, it comes from a post by Robert Strucky that is no longer on the Abode site.
Which leads me to ask if you updated your ESTK? I only tried it in ESTK. In the data browset there is a triangle icon next to err. If you click on that icon it drops down to show the properties. But description is not in that list is ESTK, which is why I posted my question about why it's not undefined. At the time I thought it wasn't a property. I found it a while back while doing a blind search for a property that I could use to match instead of the error string.
There is more than one type of error and not all are objects.
Yes, and it seems that all of the General Photoshop error type error have the same error number. Still it might be helpful to note the type of error if you are logging them.
I think that you are only using the error mechanism when you use throw without a real error so it throws what ever you give it.
Code: Select allvar stop = true;
try{
if (stop) var obj = new Object ; throw obj
}catch(e){
alert(typeof e); //object
}
I'm still looking for a way to handle General errors without using strings
Mikr
The Error Object
"Which leads me to ask if you updated your ESTK? I only tried it in ESTK. In the data browset there is a triangle icon next to err. If you click on that icon it drops down to show the properties. "
On my accursed laptop, nothing happens when you click the triagle for the 'e' or 'err' variable - there is no display of properties as there usually is, though it does record that 'e' is an Object. Be interesting to see if ti is the same on my desktop machine when it comes back.
Andrew
On my accursed laptop, nothing happens when you click the triagle for the 'e' or 'err' variable - there is no display of properties as there usually is, though it does record that 'e' is an Object. Be interesting to see if ti is the same on my desktop machine when it comes back.
Andrew