Visit Mozilla.org

Talk:Core JavaScript 1.5 Guide:LiveConnect Overview:JavaScript to Java Communication

From MDC

[edit] Java Exceptions

The getClass example doesn't work. Just trying to define getClass gives "Error: redeclaration of const getClass"

If you rename it, you get "The Java exception is internal error: Can't get Java class name usingjava.lang.Class.getName()" instead of ClassNotFoundException as the article describes.

The java.io.FileNotFound example given doesn't seem to be correct, either. First off, there is no java.io.FileNotFound, just java.io.FileNotFoundException. Second, the e instanceof java.io.FileNotFoundException is false because e is an instance of java.security.PrivilegedActionException, which is caused (eventually) by a java.io.FileNotFoundException.

try {
	var fis = new java.io.FileInputStream("fjdlkfjfjdkldjf");
} catch (e) {
	alert("Exception is " + e); //"Exception is java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException"
	alert(e instanceof java.io.FileNotFoundException) //false
	alert(netscape.javascript.JSUtil.getStackTrace(e));
	/*
	java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
		at java.security.AccessController.doPrivileged(Native Method)
		at sun.plugin.liveconnect.SecureInvocation.ConstructObject(Unknown Source)
	Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
		at java.security.AccessController.doPrivileged(Native Method)
		at sun.plugin.liveconnect.SecureInvocation$1.run(Unknown Source)
		... 2 more
	Caused by: java.lang.reflect.InvocationTargetException
		at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
		at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
		at java.lang.reflect.Constructor.newInstance(Unknown Source)
		at sun.plugin.liveconnect.PrivilegedConstructObjectAction.run(Unknown Source)
		... 4 more
	Caused by: java.io.FileNotFoundException: fjdlkfjfjdkldjf (The system cannot find the file specified)
		at java.io.FileInputStream.open(Native Method)
		at java.io.FileInputStream.(Unknown Source)
		at java.io.FileInputStream.(Unknown Source)
		... 9 more
	*/
}

This is all on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 --Np 12:06, 24 May 2007 (PDT)