Code cleanup.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
index 9c6bbfc..3dffc5e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
@@ -8,23 +8,23 @@
  */
 package com.google.eclipse.protobuf.ui.builder;
 
-import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
 import static com.google.eclipse.protobuf.ui.builder.OutputDirectories.findOrCreateOutputDirectories;
+import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
 import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PostCompilationRefreshTarget.PROJECT;
 import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType.MULTIPLE_DIRECTORIES;
 import static java.util.Collections.*;
 import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
-import static org.eclipse.core.runtime.IStatus.ERROR;
 
 import java.io.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.core.filesystem.*;
 import org.eclipse.core.resources.*;
 import org.eclipse.core.runtime.*;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.xtext.builder.IXtextBuilderParticipant;
-import org.eclipse.xtext.resource.*;
+import org.eclipse.xtext.resource.IResourceDescription;
 import org.eclipse.xtext.resource.IResourceDescription.Delta;
 
 import com.google.eclipse.protobuf.ui.preferences.pages.compiler.*;
@@ -125,7 +125,7 @@
       processStream(process.getErrorStream(), source);
       process.destroy();
     } catch (Throwable e) {
-      throw processExecutionError(command, e);
+      throw error(e);
     }
   }
 
@@ -164,8 +164,4 @@
   private static void refresh(IResource target, IProgressMonitor monitor) throws CoreException {
     target.refreshLocal(DEPTH_INFINITE, monitor);
   }
-
-  private static CoreException processExecutionError(String command, Throwable e) {
-    return new CoreException(new Status(ERROR, PLUGIN_ID, e.getMessage()));
-  }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
index ed7d6ec..d61e573 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/FileStoreDocumentContentsFactory.java
@@ -8,14 +8,12 @@
  */
 package com.google.eclipse.protobuf.ui.editor.model;
 
-import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
+import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
 import static com.google.eclipse.protobuf.util.Closeables.close;
-import static org.eclipse.core.runtime.IStatus.ERROR;
 
 import java.io.*;
 
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.ide.FileStoreEditorInput;
 import org.eclipse.xtext.resource.XtextResource;
@@ -42,9 +40,7 @@
       XtextResource resource = resourceFactory.createResource(file.toURI().toString(), contents);
       document.setInput(resource);
     } catch (Throwable t) {
-      String message = t.getMessage();
-      if (message == null) message = "";
-      throw new CoreException(new Status(ERROR, PLUGIN_ID, message, t));
+      throw error(t);
     }
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
index 89391e6..738f811 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
@@ -9,9 +9,8 @@
  */
 package com.google.eclipse.protobuf.ui.editor.model;
 
-import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
+import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
 import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
-import static org.eclipse.core.runtime.IStatus.ERROR;
 import static org.eclipse.text.undo.DocumentUndoManagerRegistry.getDocumentUndoManager;
 
 import org.eclipse.core.runtime.*;
@@ -84,10 +83,8 @@
       manager.beginCompoundChange();
       edit.apply(document);
       manager.endCompoundChange();
-    } catch (Exception e) {
-      String message = e.getMessage();
-      if (message == null) message = e.getClass().getSimpleName();
-      throw new CoreException(new Status(ERROR, PLUGIN_ID, message, e));
+    } catch (Throwable t) {
+      throw error(t);
     }
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
index 1e9a52e..a4123e5 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
@@ -8,16 +8,14 @@
  */
 package com.google.eclipse.protobuf.ui.editor.model;
 
-import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
+import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
 import static com.google.eclipse.protobuf.util.Closeables.close;
-import static org.eclipse.core.runtime.IStatus.ERROR;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.xtext.resource.XtextResource;
@@ -44,10 +42,7 @@
       XtextResource resource = resourceFactory.createResource(uri, contents);
       document.setInput(resource);
     } catch (Throwable t) {
-      String message = t.getMessage();
-      if (message == null) message = "";
-      // TODO remove duplication
-      throw new CoreException(new Status(ERROR, PLUGIN_ID, message, t));
+      throw error(t);
     }
   }
 
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java
new file mode 100644
index 0000000..0cadeb5
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.exception;
+
+import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
+import static org.eclipse.core.runtime.IStatus.ERROR;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * Factory of <code>{@link CoreException}</code>s.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public final class CoreExceptions {
+
+  public static CoreException error(Throwable cause) {
+    String message = cause.getMessage();
+    if (message == null) message = "";
+    return new CoreException(new Status(ERROR, PLUGIN_ID, message, cause));
+  }
+
+  private CoreExceptions() {}
+}