Class ExceptionLocalizer

java.lang.Object
org.daiitech.naftah.errors.ExceptionLocalizer

public final class ExceptionLocalizer extends Object
Utility class for localizing exception messages using a resource bundle.

This class provides a method to convert a Throwable into a localized string message based on its exception type. It uses a resource bundle named "exceptions" with the Arabic locale to retrieve localized messages.

Note: This class cannot be instantiated. Attempting to instantiate it will always throw a NaftahBugError.

Author:
Chakib Daii
  • Field Details

  • Constructor Details

    • ExceptionLocalizer

      private ExceptionLocalizer()
      Private constructor to prevent instantiation.

      Always throws a NaftahBugError with an Arabic message "استخدام غير مسموح به." ("Usage not allowed.") when called.

  • Method Details

    • localizeException

      public static String localizeException(Throwable e)
      Localizes the message of the given Throwable.

      Extracts the most specific cause of the exception, retrieves its simple class name as the key, and looks up the corresponding localized message from the resource bundle. If the key does not exist, a default message is used instead. The localized message is then formatted with the exception's localized message.

      Parameters:
      e - the throwable to localize
      Returns:
      the localized message string