Yesterday Miguel blogged about a nice new feature in Mono. I added the IKVM_VERBOSE_CAST environment variable to IKVM to do something similar a while ago.
public class test { public static void main(String[] args) { System.out.println((String)(Object)args); }}
C:\j>\ikvm-0.36.0.11\bin\ikvm testException in thread "main" java.lang.ClassCastException at test.main(test.java)C:\j>set IKVM_VERBOSE_CAST=1C:\j>\ikvm-0.36.0.11\bin\ikvm testException in thread "main" java.lang.ClassCastException: Object of type "System.String[], mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" cannot be cast to "System.String, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" at test.main(test.java)
Note that the assembly qualified type names are displayed, as I believe this feature is particularly useful when trying to debug issues that arise from having loaded multiple assemblies that contain the "same" types.
While writing this I discovered that both JDK 1.6 and .NET 2.0 always generate descriptive exception messages for invalid casts:
C:\j>\jdk1.6\bin\java testException in thread "main" java.lang.ClassCastException: [Ljava.lang.String; can not be cast to java.lang.String at test.main(test.java:5)
C:\j>\ikvm\bin\ikvm testException in thread "main" java.lang.ClassCastException: Unable to cast object of type 'System.String[]' to type 'System.String'. at test.main(test.java:5)
This last result is my local ikvm development version running on .NET 2.0 with a patch to enable taking the exception message from the .NET InvalidCastException, which I didn't previously do because on .NET 1.1 this message didn't contain any useful information.
Remember Me
I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.
Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)
Powered by: newtelligence dasBlog 2.3.12105.0
© Copyright 2021, Jeroen Frijters
E-mail