I am trying to stop the execution of code when an error is found. I have "error" subroutines for example.

sub lam_num_error { $mw->messageBox(-message=>"The input must be an integer."); exit; }

The exit command is exiting the program completely which is not what I want. I've also tried this.

sub lam_num_error { $mw->messageBox(-message=>"The input must be an integer."); die; }

Using die seems to stop the execution of code but still keep the main window on the screen, which is what I want. However, I'm getting some errors like this.

Tk::Error: Died at Fastenator_working.pl line 1106. main::fl_num_error at Fastenator_working.pl line 1106 main::calc_fast_loads at Fastenator_working.pl line 1096 main::run_button at Fastenator_working.pl line 815 Tk callback for .frame13.button Tk::__ANON__ at C:/MSC.Software/Patran/2008_r2/Perl_msc/site/lib/Tk.p +m line 247 Tk::Button::butUp at C:/MSC.Software/Patran/2008_r2/Perl_msc/site/lib +/Tk/Button .pm line 111 <ButtonRelease-1> (command bound to event)

I'm not comfortable with these errors even though the code is still doing what I want. Can someone explain this and possibly suggest the best way to achieve my goal? I want the code to stop, let the user make some modifications to the input in the main window and then try again without completely shutting down the program. Thank you in advance!


In reply to Die vs. Exit by shortyfw06

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.