vuhung3990
8/20/2015 - 8:57 AM

custom throwable message

custom throwable message

/**
     *  custom throwable message
     *  usage : throw new MyCustomException("Please set GridLayout's columnCount and rowCount in XML or programmatically.");
     */
    public static class MyCustomException extends RuntimeException{
        private final String message;
        private String title = "([ ERROR ])";

        /**
         * Custom throwable with message with default title
         * @param message your message
         */
        public MyCustomException(String message) {
            this.message = message;
        }

        /**
         * Custom throwable with message and title
         * @param message your message
         * @param title title of message
         */
        public MyCustomException(String message, String title){
            this.message = message;
            this.title = title;
        }

        @Override
        public String getMessage() {
            String msg = message;
            String borderString = new String(new char[msg.length() / 2]).replace("\0", "=");
            msg = "\n" + borderString + title + borderString + "\n" + msg + "\n" + borderString + new String(new char[title.length()]).replace("\0", "=") + borderString + "\n";
            return msg;
        }
    }