Class CommonRuntimeException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.venkateshamurthy.exceptional.exceptions.CommonRuntimeException
All Implemented Interfaces:
Serializable

public class CommonRuntimeException extends RuntimeException implements Serializable
CommonRuntimeException is a unified runtime exception class that can be used across the project to encapsulate error information in a structured and consistent format.

This class extends RuntimeException and adds contextual fields such as:

  • code - Application or domain-specific error code
  • detailedMessage - Detailed, formatted explanation of the error
  • timeStamp - UTC timestamp when the error was created
  • httpStatus - The HttpStatus representing the error category

The class supports message formatting with templates, placeholder substitution, and structured logging to simplify debugging and monitoring.

Example usage:


 throw ExceptionCodes.CREDENTIAL_MISSING
     .toCommonRTE(CREDENTIAL_MISSING.getDescription(),
     "Missing or invalid credential ID: {}", request.getCredentialId())
     .logInfo();
 

Another example:


 throw ExceptionCodes.CREDENTIAL_MISSING.toCommonRTE(
      new OverlappingFileLockException(), "Missing or bad credentials",
     "Missing or invalid credential ID: {credentialId}", Map.of("credentialId", request.getCredentialId()))
     .setHttpStatus(HttpStatus.BAD_REQUEST)
     .logInfo();
 

 throw ExceptionCodes.CREDENTIAL_MISSING.toCommonRTE(
      ExceptionCode.NULL_CAUSE, "Missing or bad credentials",
      "Missing or invalid credential ID: {credentialId}", request.getCredentialId())
      .setHttpStatus(HttpStatus.BAD_REQUEST)
      .logInfo();
  *
Since:
1.0
Author:
venkateshamurthy
See Also: