diff options
author | Damien George <damien.p.george@gmail.com> | 2014-05-24 23:32:19 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-05-24 23:32:19 +0100 |
commit | 7a4ddd24281a7e21eeaa697644418015cf4dd650 (patch) | |
tree | 6e1e87da8bee4f94539b98625b4deb6fd9ececd4 /unix | |
parent | ee3fd46f1383e984c968c4a82d634d7b0cea49b8 (diff) | |
download | micropython-7a4ddd24281a7e21eeaa697644418015cf4dd650.tar.gz micropython-7a4ddd24281a7e21eeaa697644418015cf4dd650.zip |
Add SystemExit exception and use it in unix/ and stmhal/ ports.
Addresses issue #598.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/main.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/unix/main.c b/unix/main.c index 23dd4be631..884ee9d32d 100644 --- a/unix/main.c +++ b/unix/main.c @@ -123,6 +123,11 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, return 0; } else { // uncaught exception + // check for SystemExit + mp_obj_t exc = (mp_obj_t)nlr.ret_val; + if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_SystemExit)) { + exit(mp_obj_get_int(mp_obj_exception_get_value(exc))); + } mp_obj_print_exception((mp_obj_t)nlr.ret_val); return 1; } @@ -383,7 +388,7 @@ STATIC mp_obj_t mp_sys_exit(uint n_args, const mp_obj_t *args) { if (n_args > 0) { rc = mp_obj_get_int(args[0]); } - exit(rc); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_SystemExit, mp_obj_new_int(rc))); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); |