PRB: System.exit() Causes a SecurityExceptionEx

ID: Q179853

The information in this article applies to:

SYMPTOMS

Calling the System.exit() method from a distrusted applet causes a security exception.

CAUSE

An untrusted applet cannot call System.exit() because it causes the browser to shut down.

RESOLUTION

If your program needs to call System.exit(), you must make the applet trusted.

STATUS

This behavior is by design.

MORE INFORMATION

The sample code below generates the following security exception:

   com.ms.security.SecurityExceptionEx[SystemExit.action]


Sample Code

   import java.awt.*;

   public class SystemExit extends java.applet.Applet
   {
      public void init()
      {
         add(new Button("Exit"),"Center");
      }
      public boolean action(Event e, Object o)
      {
         System.exit(0);
         return true;
      }
   }

REFERENCES

For additional information on making your Java Code trusted in Microsoft Internet Explorer, please refer to the following Knowledge Base article:

   ARTICLE-ID: Q193877
   TITLE     : HOWTO: Make your Java Code Trusted in Internet Explorer

For more information on making your applet trusted, please see the Microsoft SDK for Java 2.0x documentation, available at http://www.microsoft.com/java/sdk/.

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/

Additional query words: system exit trusted applet

Technology        : kbInetDev
Version           : WINDOWS:
Platform          : WINDOWS
Issue type        : kbprb
Solution Type     : kbnofix

Last Reviewed: November 10, 1998