PRB: System.exit() Causes a SecurityExceptionEx (179853)



The information in this article applies to:

  • Microsoft virtual machine
  • Microsoft Visual J++ 1.0, when used with:
    • the hardware: Intel x86
  • Microsoft Visual J++ 1.1, when used with:
    • the hardware: Intel x86
  • Microsoft Internet Explorer (Programming) 3.0, when used with:
    • the hardware: Intel x86
  • Microsoft Internet Explorer (Programming) 3.01, when used with:
    • the hardware: Intel x86
  • Microsoft Internet Explorer (Programming) 3.02, when used with:
    • the hardware: Intel x86
  • Microsoft SDK for Java 1.5
  • Microsoft SDK for Java 1.5.1
  • Microsoft SDK for Java 2.0
  • Microsoft SDK for Java 2.01
  • Microsoft SDK for Java 2.02
  • Microsoft SDK for Java 3.0
  • Microsoft SDK for Java 3.1

This article was previously published under Q179853

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, please refer to the following Knowledge Base article: For additional information on making your Java Code trusted in MicrosoftInternet Explorer, click the article number below to view the article in the Microsoft Knowledge Base:

193877 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/mscorp/java/.

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

Modification Type:MinorLast Reviewed:11/14/2005
Keywords:kbnofix kbprb KB179853