Author Topic: throw / catch exceptions with JScript  (Read 3622 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1374
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
throw / catch exceptions with JScript
« on: August 06, 2019, 08:14:11 pm »
Hi,
I have a JScript script that calls a number of functions e.g.
main >
     f1
     f2
           f2.1
           f2.2

When I run f2.1, I'd like to stop the script if a condition is verified. I'm trying to do that with exceptions but EA doesn't let me create an "Exception". I also tried to throw a random value or a null -> I'm getting a non catch exception error...
Is there any way to stop a script from a any function?

function f2()
{
   try
   {
       result = f2.1(input);
    }
   catch (e)
   {
      throw e;
    }
    f2.2(result );
}

function f2.1(in)
{
   ...
   if(errorFound)
   {
     throw new Exception();   --> EA error : Exception is undefined
    }    ...
}
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: throw / catch exceptions with JScript
« Reply #1 on: August 07, 2019, 11:57:41 am »
See:
https://www.w3schools.com/js/js_errors.asp

For JavaScript (AFAIK also applies to JScript) the syntax is like:

Code: [Select]
throw "Error message here";
If the error you are seeing is something like "Exception thrown and not caught", then it probably means that you need to add a try-catch block somewhere higher up in your script.