ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.94k stars 418 forks source link

Any way to handle error in FTXUI? #488

Closed jiande-my closed 1 year ago

jiande-my commented 2 years ago

Hi, @ArthurSonzogni, CC: @SAtacker

I have try using C++ exceptions in FTXUI, but it doesn't work properly. Any recommendation to handle errors in FTXUI.

Thanks

ArthurSonzogni commented 2 years ago

Welcome @jiande-my !

it doesn't work properly

I don't have any idea what this mean. Could you please be more specific?


Related discussion: https://github.com/ArthurSonzogni/FTXUI/discussions/451

jiande-my commented 2 years ago

@ArthurSonzogni

int main()
{
    try
    {
        MyFunc(256); //cause an exception to throw
    }

    catch (invalid_argument& e)
    {
        cerr << e.what() << endl;
        return -1;
    }
    //...
    return 0;
}

Example of C++ in Error Handling.

Do FTXUI have this kind of features. If the program have error instead stop the program display segmentation fault but instead some error message so that we know where the error is.

ArthurSonzogni commented 2 years ago

Yes, this is C++ errors. You can wrap your throwing block with try/catch if you want to handle errors. You are free to do it yourself.

FTXUI will never handle your errors for you. Also, FTXUI guarantee it works with exceptions disabled.

If you want some "global" error handling. Feel free to wrap the loop function and restart from a new ScreenInteractive.

while(true) {
  try {
    auto screen = ScreenInteractive::FitComponent();
    screen.Loop(component);
  } catch (error) {
    [...]
  }
}

Out of curiosity. Why do you need to use C++ exception at all?

ArthurSonzogni commented 1 year ago

I am archiving this, because there are no more activity.