> Try catching a more specific Exception (like ClassCastException) or
> first trying if (e instanceof HTMLEditor). And when catching an
> exception and throwing a new one it often makes sense to chain the
> exceptions with initCause().

You are right. Thanks for catching that.
It is now fixed.


2005-12-13  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/text/html/HTMLEditorKit.java
        (insertHTML): Fixed catching of exceptions.
        (getHTMLDocument): Likewise.
        (getHTMLEditorKit): Likewise.

Index: javax/swing/text/html/HTMLEditorKit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLEditorKit.java,v
retrieving revision 1.14
diff -u -r1.14 HTMLEditorKit.java
--- javax/swing/text/html/HTMLEditorKit.java	13 Dec 2005 22:15:16 -0000	1.14
+++ javax/swing/text/html/HTMLEditorKit.java	13 Dec 2005 22:46:22 -0000
@@ -60,6 +60,7 @@
 import javax.swing.text.BoxView;
 import javax.swing.text.ComponentView;
 import javax.swing.text.Document;
+import javax.swing.text.EditorKit;
 import javax.swing.text.Element;
 import javax.swing.text.IconView;
 import javax.swing.text.LabelView;
@@ -249,9 +250,15 @@
           super.getHTMLEditorKit(editor).insertHTML(doc, offset, html,
                                                     popDepth, pushDepth, addTag);
         }
-        catch (Exception e)
+      catch (IOException e)
         {
-          throw new RuntimeException(e);
+          throw (RuntimeException) new RuntimeException("Parser is null.")
+                                    .initCause(e);
+        }
+      catch (BadLocationException ex)
+        {
+          throw (RuntimeException) new RuntimeException("BadLocationException: "
+                                                        + offset).initCause(ex);
         }
       }
       
@@ -341,14 +348,10 @@
        */
       protected HTMLDocument getHTMLDocument(JEditorPane e)
       {
-        try
-        {
-          return (HTMLDocument) e.getDocument();
-        }
-        catch (Exception ex)
-        {
-          throw new IllegalArgumentException("Document is not a HTMLDocument.");
-        }
+        Document d = e.getDocument();
+        if (d instanceof HTMLDocument)
+          return (HTMLDocument) d;
+        throw new IllegalArgumentException("Document is not a HTMLDocument.");
       }
       
       /**
@@ -359,15 +362,10 @@
        */
       protected HTMLEditorKit getHTMLEditorKit(JEditorPane e) 
       {
-        try
-        {
-          return (HTMLEditorKit) e.getEditorKit();
-        }
-        catch (Exception ex)
-        {
-          throw new IllegalArgumentException(
-                                             "EditorKit is not a HTMLEditorKit.");
-        }
+        EditorKit d = e.getEditorKit();
+        if (d instanceof HTMLEditorKit)
+          return (HTMLEditorKit) d;
+        throw new IllegalArgumentException("Document is not a HTMLDocument.");
       }
       
       /**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to