[e-lang] Three problems with exceptions

Kevin Reid e-lang@mail.eros-os.org
Sat, 20 Dec 2003 18:54:47 -0500


---- Problem #1:

? [][0]
# problem: <ArrayIndexOutOfBoundsException>

So far so good.

? try { [][0] } catch p :<type:java.lang.IndexOutOfBoundsException> {
"ok" } catch _ { "not ok" }
# value: "not ok"

Unexpectedly doesn't work.

? try { [][0] } catch p ? (p.leaf() =~ pp
:<type:java.lang.IndexOutOfBoundsException>) { "ok" } catch _ { "not ok"
}
# value: "ok"

So it's possible to identify specific exceptions thrown from Java, but
absurdly complicated.

---- Problem #2:

? <import:java.lang.ArrayIndexOutOfBoundsException>
# problem: <SecurityException: java.lang.ArrayIndexOutOfBoundsException
not approved as safe>

How do I throw an exception of a Java-defined type from E?

---- Problem #3:

How do I define new exception types, and subtypes of those types, from
E? 

(Matching of these types would need to not be dependent on object
identity; otherwise they could not be practically used in distributed
applications.)

---- Complaint:

With the above problems, I am having trouble managing exceptions
appropriately in my program. 

Very slightly contrived example: 

  I have a possibly-far reference to an object which may be an EMap or
an object defined in E having a similar interface.

  If I call its get/1 method, I cannot tell an "absence of key"
exception from other exceptions without either wrapping the EMap in an E
object to rethrow the exception, or having two patterns (one of which
extracts the string from the RuntimeException that is apparently all I
can throw from E, and compares it).

  Since the reference may be far, another round-trip for maps/1 is
undesirable (and also requires my map-like objects to implement it).

Every 'catch' in my program ends up being one of:
  * ignore the exception
  * report it to the user (which probably won't be very helpful)
  * assume it's the exception I was expecting, as in the map case above

---- Um:

Is there some documentation on exceptions in E that I missed?

-- 
Kevin Reid