Answer the question
In order to leave comments, you need to log in
What approach allows you to move error handling to a separate file?
Hello,
I understand that I asked a bit obliquely, I will try to explain with an example. When we work, for example, with libusb, we write something like this
ret = libusb_init(&ctx); //Инициализация библиотеки
if (ret < 0) { //Что-то странное, libusb работать не хочет
goto init_err_mark;
}
devh = libusb_open_device_with_vid_pid(ctx, 1234, 5285);
if(devh == NULL) { //Устройство не открылось
goto devh_err_mark;
}
ret = libusb_claim_interface(devh, 0);
if(ret < 0) { //Интерфейс не открывается
goto iface_err_mark;
}
... //Собственно работаем с устройством
//Освобождаем ресурсы
libusb_release_interface(devh, 0);
iface_err_mark:
libusb_close(devh);
devh_err_mark:
libusb_exit(ctx);
init_err_mark:
return ret;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question