001    package calhoun.util;
002    
003    /** Exception type for consistency check errors.  It is unchecked to simplify error handling in other Java code.
004     * It is a wrapper for problems that arise from failed consistency checks.It is a subclass of ConfigException.
005     * You should assume error messages will be viewed by the user.
006     */
007    public class CheckException extends RuntimeException {
008    
009            private static final long serialVersionUID = 4225964190101139621L;
010    
011            public CheckException() {
012            }
013    
014            public CheckException(String arg0) {
015                    super(arg0);
016            }
017    
018            public CheckException(String arg0, Throwable arg1) {
019                    super(arg0);
020                    if(arg1.getCause() != null)
021                            initCause(arg1.getCause());
022                    else
023                            initCause(arg1);
024            }
025    
026            public CheckException(Throwable arg) {
027                    if(arg.getCause() != null)
028                            initCause(arg.getCause());
029                    else
030                            initCause(arg);
031            }
032        
033        /**
034         * Gets the plain message unembellished with stack traces and causes.
035         */
036        public String getPlainMessage() {
037            String message = super.getMessage();
038            // Strip off the bean toString when it is added to the message
039            int index = message.indexOf(": calhoun.");
040            if ( index != -1 )
041                message = message.substring(0, index);
042            return message;
043        }
044        
045            @Override
046            public String getMessage() {
047                    String ret = super.getMessage();
048                    Throwable cause = getCause();
049                    if(cause != null) {
050                            ret += " caused by: "+cause.getMessage()+" - "+cause.toString();
051                    }
052                    return ret;
053            }
054    }