<p>Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.</p></p><strong>First time visiting? Here are some places to start:</strong></p><ol style="list-style:inherit;margin-left:25px;"><li>Looking for a certain topic? Check out the <a href="https://forum.onshape.com/categories">categories filter</a> or use Search (upper right).</li><li>Need support? <a href="https://forum.onshape.com/post/question/community-support">Ask a question</a> to our <a href="https://forum.onshape.com/categories/community-support">Community Support</a> category.</li><li>Please submit support tickets for bugs but you can request improvements in the <a href="https://forum.onshape.com/categories/product-feedback">Product Feedback category</a>.</li><li>Be respectful, on topic and if you see a problem, Flag it.</li></ol><p>If you would like to contact our Community Manager personally, feel free to <a href="https://forum.onshape.com/profile/6/LouGallo">send a private message</a> or <a href="mailto:lgallo@onshape.com">an email</a>.
</p>

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

billy2
billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,204 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_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,274 image
    return;

    ?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,115 image
    break;

    ?
    Senior Director, Technical Services, EMEA
  • billy2
    billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,204 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_carr
    john_f_carr Onshape Employees Posts: 74 image
    How about
        throw regenError('Sorry, that input is too confusing');
  • billy2
    billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,204 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,