Developer Maxi Posted May 8, 2013 Developer Share Posted May 8, 2013 Hi everyone, It has come to my attention that it's not clear for everyone how to handle exception in OSBot scripts. Various pieces of code in the OSBot client throw InterruptedExceptions. Everywhere where you have a try-catch block you have to make sure you add specific clause to catch InterruptedExceptions in which you then have to throw, in front of any other catch clause. If you're only adding try-catch blocks to catch the InterruptedException, then make sure you are just adding the throws statement to the method signature and remove your try-catch block entirely. The reason this is important is because the client uses interrupted exceptions to switch behaviour, for example when the bot will switch from the script to a random executor, or when you pause your script. Here is an example: /** * Gets called recursively on the bot's main thread. * * @return The timeout to sleep after running one loop cycle. */ @Override public int onLoop() throws InterruptedException { try { scan(); switch (state) { case IDLE: return 100 + gRandom(100, 50); case STEAL: return steal(); case TO_BANK: return toBank(); case BANK: return bank(); case TO_STALL: return toStall(); } return 20 + gRandom(100, 100); } catch (InterruptedException e) { // <---- VERY IMPORTANT ----> \\ throw e; // <---- VERY IMPORTANT ----> \\ } catch (Exception e) { e.printStackTrace(); return 100 + gRandom(200, 100); } } Link to comment Share on other sites More sharing options...
shockdz Posted May 19, 2013 Share Posted May 19, 2013 People who didn't know this yet probably script in Notepad. Thanks for this Maxi, it'll help out some people. Link to comment Share on other sites More sharing options...
GoldenGates Posted May 19, 2013 Share Posted May 19, 2013 People who didn't know this yet probably script in Notepad. Thanks for this Maxi, it'll help out some people. I script with pencil and paper...and people probably didn't think this was necessary. Link to comment Share on other sites More sharing options...
Aeterna Posted May 19, 2013 Share Posted May 19, 2013 Figured throwing the exception was enough - thanks. Link to comment Share on other sites More sharing options...
Jack Posted June 25, 2013 Share Posted June 25, 2013 What happens to your script if you don't do this? Link to comment Share on other sites More sharing options...
Rick Posted July 12, 2013 Share Posted July 12, 2013 What happens to your script if you don't do this? it will get stuck. (right) Link to comment Share on other sites More sharing options...
pwnd Posted July 16, 2013 Share Posted July 16, 2013 (edited) I don't really understand why you would throw an exception that is already being thrown. You should probably add code there to handle the exception.... rather than just throw it again. People who didn't know this yet probably script in Notepad. People who can use just a text editor to program are probably above you, just sayin'. Edited July 16, 2013 by pwnd Link to comment Share on other sites More sharing options...
DJay Posted July 27, 2013 Share Posted July 27, 2013 I don't really understand why you would throw an exception that is already being thrown. You should probably add code there to handle the exception.... rather than just throw it again. People who didn't know this yet probably script in Notepad. People who can use just a text editor to program are probably above you, just sayin'. Haha, I remember when I was into RSPS coding I used to program stuff with a pencil in paper when I was bored in classes. Writing scripts is a bit more complicated for me though. :P Link to comment Share on other sites More sharing options...