“We do not use C++ exceptions” — What's the alternative? Let it crash?

前端 未结 7 433
南旧
南旧 2021-02-01 14:25

\"We do not use C++ exceptions.\"

If you don\'t use exceptions, what happens when there\'s an error? You just let the program crash?

7条回答
  •  悲&欢浪女
    2021-02-01 15:06

    Alternatives to exceptions other than return codes:

    • LISP-style conditional handler.
    • Software signals and slots, QT-style.
    • Hardware interrupt or signal handler without a stack unwind. It's the stack unwind that is the problem with exceptions on embedded devices.
    • longjmp / setjmp
    • Callback function
    • Flag value e.g. errorno (Unix), GetLastError (Windows), glGetError (OpenGL), etc.
    • Message queue, if program is event driven
    • Mutable functor. Handler object as input-output parameter, pointer is changed on error.
    • Fibers or threads with an error resolution co-routine
    • asm __int 3 or CPU-equivalent
    • Overlay instructions or trampoline functions.

    ...and many more. Many of the above-listed are embedded device friendly.

提交回复
热议问题