• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

No exception object in catch???

Engaged ,
May 31, 2015 May 31, 2015

Copy link to clipboard

Copied

I have the following catch block in the outermost function in a script.

} catch(err) {
restoreOriginalSettings ();
throw err;
}

When one of my testers runs the script he gets "Error 54: Uncaught Javascript exception: No such element. Line 399 throw err." where line 399 is the throw err statement. I assume "No such element" means that the exception object err does not exist. How can I be in a catch without an exception object? I must be missing something but I don't know what. I suppose I can wrap the throw err statement in a try/catch and swallow the exception but that does not feel right. Any suggestions? Thanks.

TOPICS
Actions and scripting

Views

515

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 31, 2015 May 31, 2015

Copy link to clipboard

Copied

What’s

throw

in the context of JavaScript?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2015 Jun 01, 2015

Copy link to clipboard

Copied

throw raises an exception. for example:

throw new Error("My custom exception");

creates a new exception object with the message "My custom exception" and raises or throws the exception. throw combined with try/catch is the way to create and handle exceptions in javascript. In my original post I was attempting to re-throw the exception caught by the catch.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2015 Jun 01, 2015

Copy link to clipboard

Copied

Interesting. The bogus exception must be coming from one of the Adobe API functions because all of the exceptions I throw in my code are of the form

throw new Error("Error message");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 31, 2015 May 31, 2015

Copy link to clipboard

Copied

In Javascript you can "throw anything", i.e. number, string, object, etc. Might be you are allowed to throw undefined exceptions, i.e. just "throw;". Then when you try to use "err" you'd get the error you described.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2015 Jun 01, 2015

Copy link to clipboard

Copied

Thanks.

Bazsl, have you tried something other than "throw" yet, "alert" for example?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2015 Jun 01, 2015

Copy link to clipboard

Copied

LATEST

No because I can't reproduce the error on my machine. A friend who is testing the script gets it. IAC, assuming Matias is correct that something in Adobe's code is throwing something other than an exception object the best solution seems to be:

catch(err) {

     try {

          throw err;

     catch(e) {}

}

since I don't know what to do with something that is not an exception.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines