Webwarp Util Exception

General

The Exception module brings you the following advantages

Class Overview

The exception module provides extended exception classes as shown below:

Exception Types

Example

Defining an exception family

Defining an exception goes as follows (the code is taken from the webwarp-util-crypt package, which is using the exception module):

import net.sf.webwarp.util.exception.ErrorCode; import net.sf.webwarp.util.exception.ExceptionType; import net.sf.webwarp.util.exception.SystemRuntimeException; /** * Exception (runtime) class for the crypt util library. */ public class CryptException extends SystemRuntimeException { @ErrorCode("Error when an unexpcted error occurred.")
public static final String ERROR_UNKNOWN = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:UnknownError"; @ErrorCode("Error when the initialization of the symmetric encryption algorithm implementation failed.") public static final String ERROR_FAILED_ALG_INIT = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:FailedAlgInit"; @ErrorCode("Error when the ressource for the encryption key was invalid or the access failed.") public static final String ERROR_INVALID_KEY = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:InvalidKeyRes"; @ErrorCode("Error when an invalid keylength was encountered (mostly 24 bit).") public static final String ERROR_INVALID_KEYLENGTH = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:InvalidKeyLength"; @ErrorCode("Error during an encryption operation.") public static final String ERROR_ENCRYPTION = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:ErrorEncrypt"; @ErrorCode("Error during a decryption operation.") public static final String ERROR_DECRYPTION = WEBWARP_UTIL_EXCEPTION_PREFIX + "crypt:ErrorDecrypt"; public CryptException(ExceptionType exceptionType, String errorCode, Object... parameters) { super(exceptionType, errorCode, parameters); } public CryptException(ExceptionType exceptionType, String errorCode, String defaultMessageText, Object... parameters) { super(exceptionType, errorCode, defaultMessageText, parameters); } public CryptException(ExceptionType exceptionType, String errorCode, String defaultMessageText, Throwable cause, Object... parameters) { super(exceptionType, errorCode, defaultMessageText, cause, parameters); } public CryptException(ExceptionType exceptionType, String errorCode, Throwable cause, Object... parameters) { super(exceptionType, errorCode, cause, parameters); } }

Special Notes

Each exception, which inherits from SytemException or SystemRuntimeException, must declare for each ErrorCode (Instance) a corresponding public static final constant. This constant must be annotated with the @ErrorCode annotation. It is planned to provide a tool (maven-plugin), which lists all found error codes in a project. This simplifies the correct creation of according error messages. 

Throwing an exception

A corresponding crypt exception can be filled with error data and parameters and finally thrown the following way:

throw new CryptException(ExceptionType.ENVIRONMENT,CryptException.ERROR_FAILED_ALG_INIT, "Could not initialize symmetric encryption algorithm.", e);

Webwarp Util