Marc and Michi,
Originally posted by Michi
The reason is that not all languages permit you to throw arbitrary types, such as Python and Java.
Originally posted by marc
For example, exceptions in Python are separate from the normal type system.
This is news to me, and I've done a little Python
What do you mean? I can throw any object as an exception in Python. Including built-in types like strings and integers.
BTW I agree with your decision with regards to keeping exceptions a separate type in Slice.
Here's some examples:
Code:
#!/usr/bin/env python
# Define an exception class.
# Note that there's nothing special about it!
class SomeException:
def __init__(self, msg, severity):
"""Create an instance of the exception class"""
self.msg = msg
self.severity = severity
def __str__(self):
"""Convert the exception to a string"""
return ("SomeException (msg:%s, severity: %d)" %
(self.msg, self.severity))
# Throw an instance of the new class
try:
raise SomeException('Bad craziness', 42)
except SomeException, e:
print 'Caught:', e