The Java library smartics exception has been released with version 0.10.0.

This library allows to design exceptions in your application and to generate reports on the error codes. The exceptioncodes-maven-plugin generates exception codes reports and has also been released to match the new features of smartics-exceptions.

One major change is the inclusion of ICU's MessageFormat. Now it is possible to use telling names for place holders instead of the numeric indices required by Java's message format class.

@ParentMessageParam("cause=0:message")
public class MyException extends BaseException {
  @MessageParam("2:host,3:port")
  private final URL url;
@ParentMessageParam("cause=0:message")
public class BaseException extends AbstractLocalizedRuntimeException {
  @MessageParam("1")
  private final String name;

You may now do this:

public class MyException extends BaseException {
  @MessageParam(":host,:port")
  private final URL url;
@ParentMessageParam("cause=causeMessage:message")
public class BaseException extends AbstractLocalizedRuntimeException {
  @MessageParam
  private final String name;

This will make it much easier if you add new properties to the base class later.

The message bundles will also be easier to read. The indexed version:

1000=The name is set to {1}. URL is ''{2}:{3}'': {0}

The new version with property names:

1000=The name is set to {name}. URL is ''{host}:{port}'': {causeMessage}

Thanks to ICU the composed messages are now also easier to handle:

  /**
   * Count of faults.
   *
   * @serial
   */
  @MessageParam
  private final int faultCount;
1001=The service has encountered {faultCount,plural,\
  =0{no faults}\
  =1{one fault}\
  other{# faults}\
 }.

 

Instead of our old proprietary format:

1001=The service has encountered {0}.
1001.0.0=no faults
1001.0.1=one fault
1001.0.m={0} faults

For more new message format features provided by ICU’s message format, please refer to their API documentation.

For details on this library please visit the project’s homepage, for changes since the last version, please consult the release report.


Link

Link

Posts

Tagcloud

Loading tagcloud ...