org.broadleafcommerce.common.exception
Class TranslatableException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.broadleafcommerce.common.exception.TranslatableException
All Implemented Interfaces:
Serializable

public abstract class TranslatableException
extends Exception

An exception whose message can be translated into a message suitable for a user.

Author:
Jeff Fischer
See Also:
Serialized Form

Field Summary
protected  int code
           
protected  Object[] messageParams
           
 
Constructor Summary
TranslatableException(int code, String message)
          Create a new exception instance
TranslatableException(int code, String message, Object[] messageParams)
          Creates a new exception instance
 
Method Summary
 int getCode()
          Retrieve the error code associated with this exception
 String getLocalizedMessage()
          Return the message to show to the user.
 String getMessageKey()
          Retrieves the message key that the i18n message will be keyed by.
 Object[] getMessageParameters()
          Retrieves the message parameters, if any, that will be used to populate any dynamic message parameters.
 String toString()
          Cause the message passed to the constructor to show up on stack trace logs
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

code

protected int code

messageParams

protected Object[] messageParams
Constructor Detail

TranslatableException

public TranslatableException(int code,
                             String message)
Create a new exception instance

Parameters:
code - an integer code that represents this exception state
message - the message that will be posted to stack traces on the console (not necessarily intended for the user)

TranslatableException

public TranslatableException(int code,
                             String message,
                             Object[] messageParams)
Creates a new exception instance

Parameters:
code - an integer code that represents this exception state
message - the message that will be posted to stack traces on the console (not necessarily intended for the user)
messageParams - An array of objects that may be used to dymanically populate a message
Method Detail

getCode

public int getCode()
Retrieve the error code associated with this exception

Returns:
the error code

getMessageKey

public String getMessageKey()
Retrieves the message key that the i18n message will be keyed by.

Returns:

getMessageParameters

public Object[] getMessageParameters()
Retrieves the message parameters, if any, that will be used to populate any dynamic message parameters.

Returns:

getLocalizedMessage

public String getLocalizedMessage()

Return the message to show to the user. The framework will first look in the localized property bundles for any messages that match the supplied error code and exception type. If not found, the regular message submitted to the constructor will be returned.

Message bundle properties have the following format:

[simple class name of exception]_[integer error code]=[localized message for this exception and code]

Overrides:
getLocalizedMessage in class Throwable
Returns:
The error message to display to the user

toString

public String toString()
Cause the message passed to the constructor to show up on stack trace logs

Overrides:
toString in class Throwable
Returns:
the non-localized version of the exception message


Copyright © 2013. All Rights Reserved.