Friday, July 28, 2006

I hate ClassCastExceptions...

...because they don't tell me what the class of the "wrong" object was. No message, just empty. Where is the difficulty in telling me, what the actual type of the object was that caused the class cast exception? I rarely see them, but when I see them it's not informative enough -- I have to run the debugger but those rare class cast exceptions are often hard to reproduce...

Sun, please add runtime type of the casted object to the ClassCastExceptions message

8 comments:

  1. Can you run your Java Application from the Eclipse Java Debugger? - Well then just set a Java Exception Breakpoint (See my blog on them).

    ReplyDelete
  2. The NPEs suck too. I don't like code that just does a throw new NullPointerException(). Why is it so difficult to write throw new NullPointerException("bla is null")? And if it's generated by the VM that it's even easier to generate a message.

    ReplyDelete
  3. been there, hated it, made Kaffe tell me the types and their class loaders when it throws such an exception a few years ago. I believe sun's done that now too with their implementation in the mustang builds.

    ReplyDelete
  4. They did in mustang! *sniffle*

    ReplyDelete
  5. They did just this in mustang

    ReplyDelete
  6. This is a regression bug in 1.4.1 and is fixed again in 1.5: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4826718

    IMHO it would be even better if they would also include the target class in the message.

    ReplyDelete
  7. As described in Gunnar, I am really wondering whether the new version of JDK (e.g., mustang) has solved the problem, namely explicitly showing which variable is null.

    Thank you very much!

    ReplyDelete
  8. Cool article as for me. It would be great to read something more concerning that matter. Thnx for giving that material.
    Joan Stepsen
    Wise geek

    ReplyDelete