0

I am using OpenCV 2.4.9 and Visual C++ 2017. I am writing video and for testing purposes tried to write a frame on a full disk.

I did

try {
    video_writer << frame;
} catch (cv::Exception& ex) {
    // Handle exception 
} catch (std::exception &e){
    // Handle exception
} catch (const std::runtime_error& error) {
    // Handle runtime error
}

on a full disk and hoped to be able to catch an exception. However I get a runtime error by the Microsoft Visual C++ Runtime Library stating "This application has requested the runtime to terminate it in an unusual way."

How would I catch this?

Amelse Etomer
  • 1,253
  • 10
  • 28
  • 1
    `...` (except that's a bad idea). If you debug, what exception do you get - or is it actually an exception? It might not be. – doctorlove Feb 14 '18 at 13:28
  • 2
    I believe OpenCV sends sig_abrt using abort() function in that case. So no, you can't catch that exception. – Dmitrii Z. Feb 14 '18 at 13:29
  • Thank you both! Debugging showed a more specific error message: "abort() has been called". – Amelse Etomer Feb 14 '18 at 13:38
  • 1
    Gald you found it. You can hook into the abort function if you want to do something specific. But you might not be able to do much by then. – doctorlove Feb 14 '18 at 13:56

1 Answers1

1

OpenCV uses abort() to notify about that issue. Since abort sends SIGABRT which is not a c++ exception, but rather a signal - you can't catch it within try catch block.

Also SIGABRT would cause your program to crash no matter what. You can still hook it and try to do some cleanups, but that won't stop program from terminating.

The only solution I met which would let you to work around that SIGABRT is described HERE

Dmitrii Z.
  • 2,287
  • 3
  • 19
  • 29