jython: how do you exit an applet early?

Discussion in 'Python' started by gcash, Feb 20, 2004.

  1. gcash

    gcash Guest

    I've written an applet using Java3D for rendering, which works fine if
    you have Java3D installed, of course.

    What I want to do is try to import the Java3D libraries and bail with an
    error message to the user if they're not there.

    You can't do "raise SystemExit" or "sys.exit(0)" because both of those
    try to kill the browser's Java VM, which a) raises a security exception
    and b) isn't what I want anyway.

    A "return" statement does the trick as an applet, but raises a
    "SyntaxError: 'return' outside function" and doesn't even run when using
    Jython from the command line to test things. (It shouldn't work as an
    applet, but at this point I was just randomly trying things in
    desperation.)

    What SHOULD I be doing?

    This is the code I'm using:

    try:
    # Java3D libraries
    from com.sun.j3d.utils.applet import MainFrame
    from com.sun.j3d.utils.behaviors.vp import *
    from com.sun.j3d.utils.image import *
    from com.sun.j3d.utils.universe import *
    from javax.media.j3d import *
    from javax.vecmath import *
    except:
    # Deal gracefully with Java3D not being installed
    class GearBox(Applet):
    def init(self):
    self.add(Label('Java3D is not properly installed.', Label.CENTER))
    if __name__ == '__main__':
    # Not running as an applet
    print 'Java3D is not properly installed.'
    raise SystemExit
    else:
    # SyntaxError: 'return' outside function
    return


    My email is gcash AT cfl.rr.com, but please post your reply to the group.

    --
    I just like saying "chlorine pentafluoride"
     
    gcash, Feb 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Miles

    Exit Custom Server Control Early

    Marc Miles, Aug 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    367
    Marc Miles
    Aug 17, 2005
  2. Jonathan Bartlett

    Using exceptions for early exit

    Jonathan Bartlett, Dec 12, 2005, in forum: Java
    Replies:
    37
    Views:
    1,192
    Oliver Wong
    Dec 16, 2005
  3. David McNab
    Replies:
    0
    Views:
    522
    David McNab
    Apr 9, 2004
  4. Divya Prakash
    Replies:
    0
    Views:
    465
    Divya Prakash
    Dec 19, 2006
  5. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    373
    Pinegar, Kent T
    Jul 24, 2008
Loading...

Share This Page