Java Exception Format formatExceptionMsg(String msg)

Here you can find the source of formatExceptionMsg(String msg)

Description

formats a message that will be displayed in a dialog, so it's not longer than 80 symbols in each line

License

Apache License

Declaration

public static String formatExceptionMsg(String msg) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from   w ww.jav a 2  s . co  m
     * formats a message that will be displayed in a dialog,
     *  so it's not longer than 80 symbols in each line
     */
    public static String formatExceptionMsg(String msg) {
        msg = msg.replace("\n", "");
        if (msg.length() > 80) {
            String result = "";
            for (int i = 0; i < msg.length(); i = i + 80) {
                int end = i + 80;
                if (msg.length() < i + 80)
                    end = msg.length();
                String s = msg.substring(i, end);
                int index = s.lastIndexOf(" ");
                if (index == -1) {
                    result = result + s + "\n";
                } else {
                    result = result + msg.substring(i, i + index) + "\n";
                    i = i - (s.length() - index);
                }
            }
            return result;
        } else
            return msg;
    }
}

Related

  1. fmtError( Exception e )
  2. formatException(final Exception e)
  3. formatException(Throwable ex)
  4. formatException(Throwable exception)
  5. formatException(Throwable th)
  6. formatJavaException(Exception e)
  7. formatLogMessage(long id, Throwable exception)
  8. formatMessage(Exception e)
  9. formatStackTrace(Exception error)