Try/Catch and threading

前端 未结 5 947
谎友^
谎友^ 2021-02-07 13:29

I have an idea why but I\'d like to ask if someone has a good grasp on why the exception raised inside a thread is never caught by the code that started it. Here\'s some very si

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 14:00

    The running thread will not be caught in your try/catch statement because it is running in another thread. Try/Catch only works for the current thread. What you need to do is have try/catch in the function being run by the thread, and have some way of managing what happens when that crash occurs.

提交回复
热议问题