TimeoutException I need stop code funcion. Java/Processing

Hello,

I have a problem with a piece of code, sometimes it is too slow. The code is responsible for testing a printer, the problem is that if the printer is offline, the program crashes for 15-20 seconds. I want that if after 2 seconds has not done the task, jump the code.

Something like a break if the time exceeds two seconds

I think it can work with try {} catch (TimeoutException e) {} but, I not know how could do exception.

I've been looking Thread and TimeoutException but not how to do.

Is there any way to do this?

thanks in advance

Answers

  • edited April 2016

    Isn't there a code processing for what I want to do?

    This is not a hardware problem, it is an attempt to fix a bug in java.

  • edited May 2016

    Thanks for anwswer Eeyorelife.

    I can solved problen with Thread

        void setup(){
                ThereadOK AAA = new ThereadOK("testing");
                AAA.start();   
            }
            int i = 0;
        void draw()
        {
          println(i); i++; delay(500);
        }
    
    
        public class ThereadOK extends Thread {
            public ThereadOK(String str) {
                super(str);
            }
            public void run() {
              try{   
                println(getName());delay(10000);println(getName());
              }catch(Error e){}
            }
        }
    

    It sample code mayby can help in future questions.

Sign In or Register to comment.