Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Important] OSBot golden scripting rule: Exception handling in OSBot

Featured Replies

  • Developer

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);
        }
    }
  • 2 weeks later...

People who didn't know this yet probably script in Notepad. Thanks for this Maxi, it'll help out some people. :)

People who didn't know this yet probably script in Notepad. Thanks for this Maxi, it'll help out some people. smile.png

I script with pencil and paper...and people probably didn't think this was necessary.

  • 1 month later...
  • 3 weeks later...

What happens to your script if you don't do this?

 

it will get stuck.

 

(right)

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.  smile.png

People who can use just a text editor to program are probably above you, just sayin'.

Edited by pwnd

  • 2 weeks later...

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.  smile.png

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

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.