more robust exception handling (amending 8cc1ae43e12e);
authorwenzelm
Fri, 24 Nov 2023 11:10:31 +0100
changeset 79045 24d04dd5bf01
parent 79044 8cc1ae43e12e
child 79046 926fc9ca7360
more robust exception handling (amending 8cc1ae43e12e);
src/Pure/General/file.scala
src/Pure/General/url.scala
--- a/src/Pure/General/file.scala	Thu Nov 23 11:40:49 2023 +0100
+++ b/src/Pure/General/file.scala	Fri Nov 24 11:10:31 2023 +0100
@@ -13,7 +13,7 @@
 import java.nio.file.{StandardOpenOption, Path => JPath, Files, SimpleFileVisitor,
   FileVisitOption, FileVisitResult}
 import java.nio.file.attribute.{BasicFileAttributes, PosixFilePermission}
-import java.net.{URI, URL, MalformedURLException, URISyntaxException}
+import java.net.{URI, URL}
 import java.util.zip.{GZIPInputStream, GZIPOutputStream}
 import java.util.EnumSet
 
@@ -41,9 +41,7 @@
       }
       else name
     }
-    catch {
-      case _: MalformedURLException | _: URISyntaxException => standard_path(name)
-    }
+    catch { case exn: Throwable if Url.is_malformed(exn) => standard_path(name) }
 
 
   /* platform path (Windows or Posix) */
--- a/src/Pure/General/url.scala	Thu Nov 23 11:40:49 2023 +0100
+++ b/src/Pure/General/url.scala	Fri Nov 24 11:10:31 2023 +0100
@@ -31,11 +31,15 @@
 
   /* make and check URLs */
 
+  def is_malformed(exn: Throwable): Boolean =
+    exn.isInstanceOf[MalformedURLException] ||
+    exn.isInstanceOf[URISyntaxException] ||
+    exn.isInstanceOf[IllegalArgumentException]
+
   def apply(name: String): URL =
     try { new URI(name).toURL }
     catch {
-      case _: MalformedURLException | _: URISyntaxException =>
-        error("Malformed URL " + quote(name))
+      case exn: Throwable if is_malformed(exn) => error("Malformed URL " + quote(name))
     }
 
   def resolve(url: URL, route: String): URL =