Permalink
Browse files

refactoring exceptions

  • Loading branch information...
csokol committed Apr 25, 2012
1 parent bf75802 commit d811460d41ae68c03e307593b057dee45ac04b0d
@@ -68,17 +68,17 @@ public void build() throws IOException {
Book b = null;
try {
b = builder.build(showNotes);
+ } catch (TubainaSyntaxErrorsException e) {
+ e.printStackTrace();
+ System.exit(-1);
} catch (TubainaException e) {
if (dontCare) {
LOG.warn(e);
} else {
e.printStackTrace();
System.exit(-1);
}
- } catch (TubainaSyntaxErrorsException e) {
- e.printStackTrace();
- System.exit(-1);
- }
+ }
RegexConfigurator conf = new RegexConfigurator();
@@ -3,44 +3,44 @@
import java.util.ArrayList;
import java.util.List;
-public class TubainaSyntaxErrorsException extends RuntimeException {
+public class TubainaSyntaxErrorsException extends TubainaException {
- List<Exception> exceptions;
+ List<TubainaException> exceptions;
public TubainaSyntaxErrorsException() {
super();
- exceptions = new ArrayList<Exception>();
+ exceptions = new ArrayList<TubainaException>();
}
- public TubainaSyntaxErrorsException(String message, List<Exception> exceptions) {
+ public TubainaSyntaxErrorsException(String message, List<TubainaException> exceptions) {
super(message);
- this.exceptions = new ArrayList<Exception>();
- for (Exception exception : exceptions) {
+ this.exceptions = new ArrayList<TubainaException>();
+ for (TubainaException exception : exceptions) {
addError(exception);
}
}
- public TubainaSyntaxErrorsException(String message, TubainaSyntaxErrorsException e) {
+ public TubainaSyntaxErrorsException(String message, TubainaException e) {
super(message);
- this.exceptions = new ArrayList<Exception>();
+ this.exceptions = new ArrayList<TubainaException>();
exceptions.add(e);
}
- public void addError(Exception t) {
- exceptions.add(t);
+ public void addError(TubainaException e) {
+ exceptions.add(e);
}
- public void addErrors(List<Exception> exceptions) {
- for (Exception throwable : exceptions) {
- this.addError(throwable);
+ public void addErrors(List<TubainaException> exceptions) {
+ for (TubainaException exception : exceptions) {
+ this.addError(exception);
}
}
@Override
public void printStackTrace() {
super.printStackTrace();
- for (Exception t : exceptions) {
- t.printStackTrace();
+ for (Exception e : exceptions) {
+ e.printStackTrace();
}
}
@@ -41,7 +41,7 @@ public Book build() {
public Book build(boolean showNotes) {
List<Chapter> chapters = new ArrayList<Chapter>();
- List<Exception> exceptions = new ArrayList<Exception>();
+ List<TubainaException> exceptions = new ArrayList<TubainaException>();
for (Reader reader : readers) {
LOG.info("Parsing chapter " + (chapterCount + 1));
Scanner scanner = new Scanner(reader);
@@ -50,7 +50,7 @@ public Book build(boolean showNotes) {
try {
chapters.addAll(parse(scanner.next()));
}
- catch(Exception e) {
+ catch(TubainaException e) {
exceptions.add(e);
}
}
@@ -68,7 +68,7 @@ public Book build(boolean showNotes) {
List<Chapter> chapters = new ArrayList<Chapter>();
- List<Exception> exceptions = new ArrayList<Exception>();
+ List<TubainaException> exceptions = new ArrayList<TubainaException>();
Integer offset = 0;
@@ -92,7 +92,7 @@ public Book build(boolean showNotes) {
try {
Chapter chapter = new ChapterBuilder(title, introduction, content).build();
chapters.add(chapter);
- } catch (Exception e) {
+ } catch (TubainaException e) {
exceptions.add(e);
}
@@ -7,6 +7,7 @@
import br.com.caelum.tubaina.Chapter;
import br.com.caelum.tubaina.Section;
+import br.com.caelum.tubaina.TubainaException;
import br.com.caelum.tubaina.TubainaSyntaxErrorsException;
import br.com.caelum.tubaina.chunk.IntroductionChunk;
import br.com.caelum.tubaina.resources.Resource;
@@ -33,7 +34,7 @@ public Chapter build() {
List<Section> sections = new ArrayList<Section>();
List<Resource> resources = new ArrayList<Resource>();
- List<Exception> exceptions = new ArrayList<Exception>();
+ List<TubainaException> exceptions = new ArrayList<TubainaException>();
if (content != null && content.trim().length() > 0) {
Integer offset = 0;
@@ -14,16 +14,16 @@
private final List<Replacer> replacers = new ArrayList<Replacer>();
public List<Chunk> make(String text) {
- List<Exception> exceptions = new ArrayList<Exception>();
+ List<TubainaException> exceptions = new ArrayList<TubainaException>();
List<Chunk> chunks = new ArrayList<Chunk>();
while (text.trim().length() != 0) {
boolean accepted = false;
for (Replacer replacer : replacers) {
- if(replacer.accepts(text)) {
+ if (replacer.accepts(text)) {
try {
text = replacer.execute(text, chunks);
accepted = true;
- } catch (Exception e) {
+ } catch (TubainaException e) {
exceptions.add(e);
}
break;

0 comments on commit d811460

Please sign in to comment.