Prev | Index | Next |
Exceptions work mostly the same as in C++ - there are try blocks, catch blocks, and throw statements. One difference is that you can't catch an abstract class. This is because object variables in the catch clause aren't implemented in the same way as regular object variables - they can't hold any subtype of the object type, as described in the polymorphism section, due to implementation difficulties. Parameters to catch clauses work like parameters in C++, and truncate the object they catch. This isn't usually a problem, because C++ already causes subtypes of the type to be caught by the earlier catch clauses. This restriction might be lifted in the future.
In the meantime, since abstract classes can't truncate the object they're storing, they aren't allowed as parameters to catch clauses. Otherwise, pretty much any type can be thrown or caught.
Throw declarations in function headers have not yet been implemented in C*. There was little enforcement of the throw types in C++, causing them to serve more as documentation than actual restrictions. Careful thought and investigation must be conducted before putting them in C* to determine whether the rules surrounding throw clauses should be changed compared to C++. In the meantime, anything can be thrown from any function and any type of error can be handled in a try/catch block.
Prev | Index | Next |