Microsoft XPS Format - Java Implementation?

Posted by Mike Haller on Sunday, January 28. 2007 at 04:05 in Java
Does anyone know about an implementation of Microsoft Vista's XPS Format? XPS stands for XML Paper Specification.

Also a nice thing which will probably come up by time are converter tools like XPS2PDF or PDF2XPS, although the latter seems to be rather complicated. Microsoft provides the XPS Specification for free, so it should not be a problem to develop libraries which can read, write, convert or analyse such documents.

The right place to look our for more information is the MSDN Forum for XPS

Why swallowing Exceptions is a bad idea

Posted by Mike Haller on Monday, January 22. 2007 at 11:56 in Java
Consider the following code

      try {
       // Some code throwing exceptions but you
       // have no idea what to do with each different
       // kind, so you just catch all Exceptions
      }
      catch( Exception e )
      {
         throw new TechnicalException( e.getMessage() );
      }


Most people forget that unchecked runtime Exceptions are also Exceptions. Thus, a catch(Exception) will also catch, for example, a NullPointerException. Now, he creates a TechnicalException with the message of the NullPointerException. This has two major draw backs:

First, it draws the stack trace useless. You won't be able to tell which of the lines in the above code has actually thrown the exception.

Secondly, the message of a NullPointerException is null, which means that the TechnicalException has no additional information. It has no usable information at all. It's absolutely meaningless.

Please please use Exception chaining. Or at least add logging. Just do something.

A slightly better way is this, but it's still horrible:

      try {
       // Some code throwing exceptions but you
       // have no idea what to do with each different
       // kind, so you just catch all Exceptions
      }
      catch( Exception e )
      {
         throw new RuntimeException( "Error while trying to do something", e );
      }


At least, it provides you with the information you need to analyze what happened by viewing the stack traces.

Edit: Btw, The Daily WTF has a nice example on how to NOT do it.

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch