Added exception hierarchy except for OSError and UnicodeError (requires arguments). Comment out the errors that aren't needed if memory becomes an issue.

This commit is contained in:
Rachel Dowdall
2014-03-22 15:28:16 +00:00
parent 249b9c761d
commit 721c55dced
5 changed files with 574 additions and 26 deletions

View File

@@ -77,23 +77,78 @@ const mp_obj_type_t mp_type_ ## exc_name = { \
.bases_tuple = (mp_obj_t)&mp_type_ ## base_name ## _base_tuple, \
};
// List of all exceptions, arranged as in the table at:
// http://docs.python.org/3.3/library/exceptions.html
MP_DEFINE_EXCEPTION_BASE(BaseException)
MP_DEFINE_EXCEPTION(AssertionError, BaseException)
MP_DEFINE_EXCEPTION(AttributeError, BaseException)
MP_DEFINE_EXCEPTION(ImportError, BaseException)
MP_DEFINE_EXCEPTION(IndentationError, BaseException)
MP_DEFINE_EXCEPTION(IndexError, BaseException)
MP_DEFINE_EXCEPTION(KeyError, BaseException)
MP_DEFINE_EXCEPTION(NameError, BaseException)
MP_DEFINE_EXCEPTION(SyntaxError, BaseException)
MP_DEFINE_EXCEPTION(TypeError, BaseException)
MP_DEFINE_EXCEPTION(ValueError, BaseException)
MP_DEFINE_EXCEPTION(OverflowError, BaseException)
MP_DEFINE_EXCEPTION(OSError, BaseException)
MP_DEFINE_EXCEPTION(NotImplementedError, BaseException)
MP_DEFINE_EXCEPTION(StopIteration, BaseException)
MP_DEFINE_EXCEPTION(ZeroDivisionError, BaseException)
MP_DEFINE_EXCEPTION(SystemExit, BaseException)
//MP_DEFINE_EXCEPTION(KeyboardInterrupt, BaseException)
MP_DEFINE_EXCEPTION(GeneratorExit, BaseException)
MP_DEFINE_EXCEPTION(Exception, BaseException)
MP_DEFINE_EXCEPTION_BASE(Exception)
MP_DEFINE_EXCEPTION(StopIteration, Exception)
MP_DEFINE_EXCEPTION(ArithmeticError, Exception)
MP_DEFINE_EXCEPTION_BASE(ArithmeticError)
MP_DEFINE_EXCEPTION(FloatingPointError, ArithmeticError)
MP_DEFINE_EXCEPTION(OverflowError, ArithmeticError)
MP_DEFINE_EXCEPTION(ZeroDivisionError, ArithmeticError)
MP_DEFINE_EXCEPTION(AssertionError, Exception)
MP_DEFINE_EXCEPTION(AttributeError, Exception)
MP_DEFINE_EXCEPTION(BufferError, Exception)
MP_DEFINE_EXCEPTION(EnvironmentError, Exception)
MP_DEFINE_EXCEPTION(EOFError, Exception)
MP_DEFINE_EXCEPTION(ImportError, Exception)
MP_DEFINE_EXCEPTION(IOError, Exception)
MP_DEFINE_EXCEPTION(LookupError, Exception)
MP_DEFINE_EXCEPTION_BASE(LookupError)
MP_DEFINE_EXCEPTION(IndexError, LookupError)
MP_DEFINE_EXCEPTION(KeyError, LookupError)
MP_DEFINE_EXCEPTION(MemoryError, Exception)
MP_DEFINE_EXCEPTION(NameError, Exception)
MP_DEFINE_EXCEPTION_BASE(NameError)
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
MP_DEFINE_EXCEPTION(OSError, Exception)
// Probably don't need these
/*MP_DEFINE_EXCEPTION_BASE(OSError)
MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
MP_DEFINE_EXCEPTION(ConnectionError, OSError)
MP_DEFINE_EXCEPTION(BrokenPipeError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionAbortedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionRefusedError, ConnectionError)
MP_DEFINE_EXCEPTION(ConnectionResetError, ConnectionError)
MP_DEFINE_EXCEPTION(FileExistsError, OSError)
MP_DEFINE_EXCEPTION(FileNotFoundError, OSError)
MP_DEFINE_EXCEPTION(InterruptedError, OSError)
MP_DEFINE_EXCEPTION(IsADirectoryError, OSError)
MP_DEFINE_EXCEPTION(NotADirectoryError, OSError)
MP_DEFINE_EXCEPTION(PermissionError, OSError)
MP_DEFINE_EXCEPTION(ProcessLookupError, OSError)
MP_DEFINE_EXCEPTION(TimeoutError, OSError)*/
MP_DEFINE_EXCEPTION(ReferenceError, Exception)
MP_DEFINE_EXCEPTION(RuntimeError, Exception)
MP_DEFINE_EXCEPTION_BASE(RuntimeError)
MP_DEFINE_EXCEPTION(NotImplementedError, RuntimeError)
MP_DEFINE_EXCEPTION(SyntaxError, Exception)
MP_DEFINE_EXCEPTION_BASE(SyntaxError)
MP_DEFINE_EXCEPTION(IndentationError, SyntaxError)
MP_DEFINE_EXCEPTION_BASE(IndentationError)
MP_DEFINE_EXCEPTION(TabError, IndentationError)
MP_DEFINE_EXCEPTION(SystemError, Exception)
MP_DEFINE_EXCEPTION(TypeError, Exception)
MP_DEFINE_EXCEPTION(ValueError, Exception)
//TODO: Implement UnicodeErrors which take arguments
MP_DEFINE_EXCEPTION(Warning, Exception)
MP_DEFINE_EXCEPTION_BASE(Warning)
MP_DEFINE_EXCEPTION(DeprecationWarning, Warning)
MP_DEFINE_EXCEPTION(PendingDeprecationWarning, Warning)
MP_DEFINE_EXCEPTION(RuntimeWarning, Warning)
MP_DEFINE_EXCEPTION(SyntaxWarning, Warning)
MP_DEFINE_EXCEPTION(UserWarning, Warning)
MP_DEFINE_EXCEPTION(FutureWarning, Warning)
MP_DEFINE_EXCEPTION(ImportWarning, Warning)
MP_DEFINE_EXCEPTION(UnicodeWarning, Warning)
MP_DEFINE_EXCEPTION(BytesWarning, Warning)
MP_DEFINE_EXCEPTION(ResourceWarning, Warning)
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) {
return mp_obj_new_exception_msg_varg(exc_type, NULL);