Jump to content
Korean Random
Pavel3333

Эквивалент try/except в Си

Recommended Posts

Есть ли эквивалент try/except в Си-питон коде, когда нужно отловить какое-либо исключение?

 

К примеру, вот такое:

try:
  a = b.c
except AttributeError:
  a = None

как можно перевести в Си-питон код? (про код ошибки PyObject_GetAttrString() знаю, но интересует именно си-питон код try/except)

Edited by Pavel3333

Share this post


Link to post

Short link
Share on other sites

@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 by Pavel3333

Share this post


Link to post

Short link
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...