2 * unexpected file format founded exception
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sourceforge.mikutoga.parser;
12 * 必要に応じて、パースに失敗した位置を保持する。
14 @SuppressWarnings("serial")
15 public class MmdFormatException extends Exception {
17 private final long position;
22 public MmdFormatException(){
29 * @param message エラーメッセージ
31 public MmdFormatException(String message){
38 * @param position 入力ソース先頭から数えたエラー位置。(バイト単位)
39 * 負の値を与えると、エラー位置は無効と解釈される。
41 public MmdFormatException(long position){
48 * @param message エラーメッセージ
49 * @param position 入力ソース先頭から数えたエラー位置。(バイト単位)
50 * 負の値を与えると、エラー位置は無効と解釈される。
52 public MmdFormatException(String message, long position){
54 this.position = position;
60 * 有効なエラー発生位置を保持している場合、追加出力される。
61 * @return {@inheritDoc}
64 public String getMessage(){
65 StringBuilder result = new StringBuilder();
67 String msg = super.getMessage();
68 if(msg != null) result.append(msg);
73 .append(this.position)
77 if(result.length() <= 0) return null;
79 return result.toString();
84 * @return 入力ソース先頭からのバイト数で表されるエラー位置。
87 public long getPosition(){
92 * 有効なエラー位置が設定されているか判定する。
93 * @return エラー位置が有効(非負)ならtrue
95 public boolean hasPosition(){
96 if(this.position < 0L) return false;