Pavel3333 Posted May 13, 2018 Share Posted May 13, 2018 (edited) Есть ли эквивалент try/except в Си-питон коде, когда нужно отловить какое-либо исключение? К примеру, вот такое: try: a = b.c except AttributeError: a = None как можно перевести в Си-питон код? (про код ошибки PyObject_GetAttrString() знаю, но интересует именно си-питон код try/except) Edited May 13, 2018 by Pavel3333 @ Quote Link to comment Short link Share on other sites More sharing options...
Mixaill Posted May 13, 2018 Share Posted May 13, 2018 Если конкретно питоновые - PyErr_Occurred() https://docs.python.org/2/c-api/exceptions.html Синтаксического сахара не будет. 1 @ Quote Link to comment Short link Share on other sites More sharing options...
Pavel3333 Posted May 13, 2018 Author Share Posted May 13, 2018 @Mixaill спасибо! @ Quote Link to comment Short link Share on other sites More sharing options...
Pavel3333 Posted June 4, 2018 Author Share Posted June 4, 2018 (edited) @Mixaill еще раз, как ее юзать? Вот, например, код: PyObject* g_gui = PyImport_ImportModule("gui.mods.mod_mods_gui"); //тут может сработать исключение, но мне этого не надо if(g_gui) {} //инициализируем ангарные настройки else {} //иначе подгружаемся с конфига PS: Решено. g_gui = PyImport_ImportModule("gui.mods.mod_mods_gui"); if (!g_gui) { PyErr_Clear(); PySys_WriteStdout("g_gui module is NULL!\n"); return; } else { PySys_WriteStdout("g_gui module loaded OK!\n"); } Edited June 4, 2018 by Pavel3333 @ Quote Link to comment Short link Share on other sites More sharing options...
SkepticalFox Posted June 4, 2018 Share Posted June 4, 2018 5 hours ago, Pavel3333 said: PS: Решено. Ну это очевидно было) 1 @ Quote Link to comment Short link Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.