How to stop program excecution...

Hi..
I would like to know how I can stop the execution of a program, not using System.out.exit(..). I do not want the application be closed.
Let me be more specific..
My program reads text from a file and depending a condition (ie. if the length of the string is > 10 , a counter is incremented , errors++ ) and I want that when errors > 20 the program stops... I use a Class that inherits from Exception class and I use it to catch when errors > 20, but the program does not stop until the end of file in reached...
just a message is shown (ie. Too many errors...)
This is a very general idea of my program...
/*class constructors and call to starts method*/
public void starts(){
int errors;
String line;
   /* another declarations */ 
  while (!myFile.eof()){
    readString();
public void readString(){
    /* code...
    line=myFile.readLine();
    if(line.length()>10){
       try{
         countErrors();
       }catch(MyException e){
         System.out.println("Too many errors " + e);
public void countErrors()throws MyException{
    if((++errors)>20)           
       throw new MyException(errors);   
class MyException extends Exception{
int error;
     public MyException(int e){
          error=e;
     public String toString() {
         return "MyException[" + error+ "]";
}An also, I use recursion in another calls to other methods so, I need solve this problem...
Any help will be useful...thanks
carrillomx

instead of throwing an exception you could just check amount of erros in the while loop and ...
if(errors > maxerrors)break;
this will exit your while loop and stop the reading of the file.. so it wud look like :
public void starts(){
int errors;
String line;
/* another declarations */
while (!myFile.eof()){   
readString();
if(errors > 20) break; checks to c amount of errors and then breaks
// the break will then quit the while loop and cancel the file
// being read without quiting the program
public void readString(){   
/* code...
line=myFile.readLine();
if(line.length()>10) errors++;

Similar Messages

  • How to stop programs running in backroune, how to stop programs running in backround

    My mac book pro is running slowly.  I was told it was because of programs running in backround.  How do I stop them.

    First, back up all data immediately, as your boot drive may be failing.
    If you have more than ten or so files or folders on your Desktop, move them, temporarily at least, somewhere else in your home folder.
    If iCloud is enabled, disable it.
    Disconnect all wired peripherals except keyboard, mouse, and monitor, if applicable. Launch the usual set of applications you use when you notice the problem.
    Step 1
    Launch the Activity Monitor application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running Mac OS X 10.7 or later, open LaunchPad. Click Utilities, then Activity Monitor in the page that opens.
    Select the CPU tab.
    Select All Processes from the menu in the toolbar, if not already selected.
    Click the heading of the % CPU column in the process table to sort the entries by CPU usage. You may have to click it twice to get the highest value at the top. What is it, and what is the process? Also post the values for % User, % System, and % Idle at the bottom of the window.
    Select the System Memory tab. What values are shown in the bottom part of the window for Page outs and Swap used?
    Step 2
    You must be logged in as an administrator to carry out this step.
    Launch the Console application in the same way as above. Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
    Post the 50 or so most recent messages in the log — the text, please, not a screenshot.
    Important: Some personal information, such as your name, may appear in the log. Edit it out before posting.

  • [Debugging help] How to stop program at certain criterion

    Dear experts,
    I would like to ask for a debugging skill.
    I have a table loop about 1000 records. There is a variant ID, I would like to stop when ID equals a value like 'XXXXX'.
    How can I set up breakpoint to make loop stop when ID='XXXXX'
    Thank you

    Or you can set break point in your code:
    IF ID='XXXXX'.
    break-point.
    * or break <your username>
    ENDIF.
    regards,

  • Can't figure out how to stop my MBP from opening programs at startup, namely word and messages

    Recenty my MBPro has started opening MS Word and Messages at startup and I can't figure out how to stop it?  I've tried selecting and de-selcting the startup option from the dock but this doesn't help.  Does anyone have any suggestions?

    System Preferences has a setting for this.
    In the Users & Groups section you will fine a "Login Items" header.  This is a list of all the programs that will open automatically when you log in.  You can select any program and click the [--] button below that window to stop the program from opening automatically.

  • How to stop a while loop in LabVIEW from a C program

    How to stop  a while loop in LabVIEW from a C code

    hi
    I think by creating dll you can stop the while loop from your C program.For that you just create dll (Dynamic Link Library) for the VI which has that while loop.
         Anyway can u please explain ur requirement clearly.

  • Ios 7.0.2 issue: how to stop running programs

    I am a new iPhone5 user and just installed ios 7.0.2 (maybe I should not have but I did). Now I don't know how to stop running programs. Previously
    I double-clicked the Home button, then saw the icons that represented running programs, then could lightly touch one of them which led to all of them
    showing a X for a potential delete. That does not work now so how do I do it?

    Double click the home button and then swipe up on the app screenshots.

  • How to stop an ORB server in other program

    I have writen an ORB server program, just like the sample HelloServer, the main thread wait on a new object forever.
    How to stop the server in some other programs?
    Is there some common method to stop ORB server except kill the main process.
    Thank for any help!

    The question I have is how to stop an orb server programmatically without shutting down my app. My app is a server that runs continuously. I want the ability to shut down just the orb portion and restart it if desired.
    I also look for this capability. When searching for this in the forums, surprisingly, I only find one question for this, but no reply or answer. Does anyone have any idea?
    Thank you for all ideas.

  • How do I stop programs opening automatically when i log onto my macbook?

    When I log onto my macbook, about 6 programs open automatically. they are not listed on my 'Login Items' and I dont know how to stop them popping up.
    Any help would be appreciated!!

    You do not clarify which email client you are using
    For Mac's mail the only way I know for more control is the Mail AttachmentTamer a easy and free to use plug-in
    http://lokiware.info/Attachment-Tamer

  • How do I stop programs from running in the background?

    How do I stop programs from running in the background?  In the old system you could delete them.

    Most of those apps aren't running in the background, but what you are asking is how to close the apps.
    To close an app in iOS 7, drag the app up from the multitasking display. Double tap the home button and you will see apps lined up going left to right across the screen. Swipe to get to the app that you want to close and then swipe "up" on the app preview thumbnail to close it.

  • My MacBook Pro switches automatically from a program to finder while working.  Can anyone make suggestions on how to stop this?

    My MacBook Pro will automatically jump from a program (Safari, Excel, etc.) to the Finder window.  Can anyone tell me how to stop this?

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of certain system caches. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled on some models, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including sound output and  Wi-Fi on certain models. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • How do i stop programs from automatically running when i start up my macbook?

    how do i stop programs from automatically running when i start up my macbook?
    programs such as.. email and Skype.
    When i go to system preferences, then users & groups, then to my name, log in items ....this box is clear, i have unchecked everything, yet things still start up......

    sometimes these applications will have a setting in the preferences to not open on login of computer. If you see none of that, you can go into:
    system preferences> Users & Groups > Select your user>Login Items.
    unlock the settings by hitting the lock icon on the bottom left of the window then youll be able to uncheck these things from opening when you log in.
    Hope this is helpful or answers the question.

  • How can i stop programs from automatically loading during startup?

    how can i stop programs from automatically loading during startup?

    Go to the Apple menu > System Preferences > Users & Groups and click on the user in question then on "Login Items."
    Also check the Startupitems folder: OS X Yosemite: If you have problems with startup items

  • I have itunes set up to sync with my Ipod Touch and my Ipad.  As of today, it keeps looking for an iPhone to sync with and give me an error message.  I don't have an iPhone and don't know how to stop it from popping open with this error message.

    I have Itunes set up to sync with my Ipod touch and Ipad.  As of today, iTunes has started searching to sync with an iPhone, which I don't have and pops open with an error message stating it cannot locate the iPhone to sync.  I have looked in devices and only the iPad and iPod Touch are listed.  Any ideas on how to stop iTunes from searching for any iPhone it is never going to find? It is annoying to have it popping up all the time with the error message.  Thanks in advance for any suggestions.

    You should really read the manual.
    "How do you restore from backup? "
    Restore.  When given the choice, choose to use backup.
    "And how can I check to see if the pics and videos are on my computer somewhere first??"
    They would only be where you put them.  What program did you use to import them?  Pics/vids taken with ipod are not part of the sync process at all.  You should be importing them just as you would with any digital camera.
    If you did not import them, then they are not on your computer.

  • How to stop while loop

    I can't figure out how to stop a while loop in my labview program. 
    When the user presses the Run arrow in the toolbar I want my program to begin reading the serial port for GPS messages.  These messages should be displayed on the front panel.  Currently I have this read/display in a while loop.  The program is also waiting for an extrenal trigger.  When that trigger arrives, I want to grab the current string from the serial port and save it and continue reading and displaying the serial/gps string.  This trigger starts the other parts of the program- signal generation, recording, and saving data which need to run concurrently with the serial/gps reading/displaying.  Once the AO and AI have finished and the data have been written to disk, I want the program to stop.  The serial/gps messages should be updating this whole time.  Only when the data are written to disk should the whole program end.  This whole sequence of events should only be done once when the user preses the Run arrow. 
    So far I'm unable to pluck the serial string when the trigger comes in if I'm watching the serial port all the time.  The program also doesn't stop when it finishes writing to disk because the read serial while loop is still running.  I don't want to use a front panel stop button.  The program should stop itself when the data havebeen written. 
    I'm really stumped on this one but I'm new to LabVIEW so I'm sure there's an easy solution to this. 
    Thanks for any and all help. 
    Attachments:
    SPoleLakeChirp.vi ‏199 KB

    Dennis and altenbach-  Thank you both for your patience. 
    I was trying to do just what Dennis suggested-"As I said, setting a local variable is one way." even before posting to this forum, but I couldn't get my local variables to reflect changes made elsewhere in the program and I wasn't able to wire from them because they were writes.  The critical part I was missing was how to change a local variable from a write to a read.  It was staring me in the face the whole time- just right click.  When I finally found it, my problems were solved. 
    altenbach- thank's for putting the figures together.  I do understand the logic and wiring there, but I was really trying to avoid stop buttons.  The program should be smart enough to figure out when to stop.  And using local variables turns out to be one way of solving this.  I still have some clean up to do, but I've included my current working version just so you can see how I implimented your suggestions.  There's still a lot of clean up to be done, but I'm delighted to be able to watch the serial/gps messages until I'm done reading in data.  At first I had this stop variable set in the final sequence frame.  That didn't work because I wasn't getting to the final frame because the loop wasn't finishing.  Once I placed the stop variable in the same frame as the while loop it began stopping when it should. 
    If you have other comments/critiques about the wiring diagram I'm earger to hear them.  I'm considering the structure finished, however.  It still needs cleaning up and commenting, but I'm satisfied with the functionality. 
    Thanks,
    Peter
    Attachments:
    SPoleLakeChirp.vi ‏210 KB

  • How to stop while loop when a specified function is terminated?

    I want to make a program which has 2 thread, one of which is to control some devices, and the other is to measure outputs of the devices.
    To do that, I should make a 2 independent loops, but there comes a problem here.
    I want to terminate 2 loops at the same time, but it's difficult for me to do that, because when I try to notify upper sequence's termination to lower loop by some value change, they have some dependency.
    That's why I need your help. I want to know how to stop lower loop when the upper sequence's termination keeping their independency.
    Please let me know. Thank you.
    Attachments:
    help.JPG ‏200 KB

    Is the upper loop commanding the lower loop at all?  I would think you would have some type of communication between the loops.  Just use that communication to send a stop command.  Or the next best way is to just simply use a notifier.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for