Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

quit(), exit() or stop()?

billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
edited July 2016 in FeatureScript
Let's say I'm checking a bunch of imported data and I decide to just give up.

<div>&nbsp; &nbsp; &nbsp;println('there\'s no data to read\nplease readData first');
<span style="font-family: Flama, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; quit();</span></div>

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    return;

    ?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,680
    break;

    ?
    Senior Director, Technical Services, EMEAI
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    return; leaves a function and returns you to the calling function, I need all feature script to die.

    break; leaves a loop, I'm not in a loop.

    In php it's called exit; it kills everything.

    I'm using return(true) & return(false) to guard entire blocks of code from executing which works but its really ugly.

    So I'm converting readData.csv into a vector array using a function and if things aren't correct I want to post a note and quit. Using return(false) means I have to handle this every time I call this function which is really ugly.


    Another way to handle this is to give me an onload() function, remember this is like javascript. Do you have this? A way to execute a function onload? Onload() converts readData.csv into vectors. Sweet, then my vector array is ready for all subsequent feature function calls.





  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    How about
        throw regenError('Sorry, that input is too confusing');
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    edited July 2016
    I like throw regenError('Sorry, that input is too confusing');

    Script running:


    Script error and I capture event:



    Throw error:


    I like this because the feature goes red indicating an error. Not sure I like all to links to broken code. Maybe there should be a silent mode that doesn't include these links.

    throw error('works');

    Thanks John,

Sign In or Register to comment.