Class ExceptionContext

  • Direct Known Subclasses:
    UnexpectedExceptionContext

    public class ExceptionContext
    extends java.lang.Object
    Wraps an Exception and allows extra contextual information to be added, such as what was happening at the time of the Exception, and a hint as to what the user might do to correct the problem. Also implements a number of methods to format the data of an Exception.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Throwable exception  
      protected java.lang.String hint  
      protected java.lang.String operation  
      protected java.lang.String prefaceString  
    • Constructor Summary

      Constructors 
      Constructor Description
      ExceptionContext​(java.lang.Throwable ex, java.lang.String operation, java.lang.String hint)
      Create a new Exception Context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getClipboardString​(boolean includeSysInfo)
      Get a String form of this Context for use in pasting to Clipboard.
      java.lang.Throwable getException()
      Get the Exception being wrapped.
      java.lang.String getHint()
      Get suggestion to the user to correct the problem.
      java.lang.String getOperation()
      Get what was happening when the exception occurred.
      java.lang.String getPreface()
      Used to give a more friendly message.
      java.lang.String getStackTraceAsString​(int maxLevels)
      Returns up to the given number of stack trace elements concatenated into one string.
      java.lang.String getStackTraceString()
      Get the Full Stack Trace String.
      java.lang.String getSummary()
      Returns a user friendly summary of the Exception.
      java.lang.String getTitle()
      Get a String to use as the Title for this Context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • exception

        protected final java.lang.Throwable exception
      • operation

        protected java.lang.String operation
      • hint

        protected java.lang.String hint
    • Constructor Detail

      • ExceptionContext

        public ExceptionContext​(@Nonnull
                                java.lang.Throwable ex,
                                @Nonnull
                                java.lang.String operation,
                                @Nonnull
                                java.lang.String hint)
        Create a new Exception Context.
        Parameters:
        ex - the Throwable Exception which has occurred.
        operation - An Operation which was taking place at the time of the Exception. Use empty String if unknown.
        hint - A hint as to what might have caused the Exception. Use empty String if unknown.
    • Method Detail

      • getException

        public java.lang.Throwable getException()
        Get the Exception being wrapped.
        Returns:
        the Exception.
      • getPreface

        public java.lang.String getPreface()
        Used to give a more friendly message.
        Returns:
        the Preface String.
      • getOperation

        public java.lang.String getOperation()
        Get what was happening when the exception occurred.
        Returns:
        empty String if unknown.
      • getHint

        @Nonnull
        public java.lang.String getHint()
        Get suggestion to the user to correct the problem.
        Returns:
        empty string if no hint, else the hint text.
      • getTitle

        public java.lang.String getTitle()
        Get a String to use as the Title for this Context.
        Returns:
        Localised Exception message, truncated to 80 chars.
      • getSummary

        public java.lang.String getSummary()
        Returns a user friendly summary of the Exception. Empty data is excluded.
        Returns:
        A string summary.
      • getStackTraceAsString

        public java.lang.String getStackTraceAsString​(int maxLevels)
        Returns up to the given number of stack trace elements concatenated into one string.
        Parameters:
        maxLevels - The number of stack trace elements to return.
        Returns:
        A string stack trace.
      • getStackTraceString

        public java.lang.String getStackTraceString()
        Get the Full Stack Trace String.
        Returns:
        unabridged Stack Trace String.
      • getClipboardString

        public java.lang.String getClipboardString​(boolean includeSysInfo)
        Get a String form of this Context for use in pasting to Clipboard.
        Parameters:
        includeSysInfo - true to include System Information, false for just the Exception details.
        Returns:
        String for use in Clipboard text.