Questions tagged [terminate-handler]

14 questions
11
votes
1 answer

In which thread is the terminate handler called?

In which thread is called the terminate handler: when an exception is thrown inside a noexcept function? when the user call std::terminate()? at start up or destruction of thread? Is it defined in the standard, will I have access to thread_local…
Oliv
  • 17,610
  • 1
  • 29
  • 72
11
votes
1 answer

Must user provided terminate() function be thread-safe?

As stated in http://en.cppreference.com/w/cpp/error/terminate there are many reasons to call terminate. I can imagine case where just almost in the same time some of these reasons happen in two threads. Q1 Can the terminate function set by…
PiotrNycz
  • 23,099
  • 7
  • 66
  • 112
10
votes
1 answer

set_terminate function is not working for me

I have the following code taken from cplusplus.com: // set_terminate example #include #include #include using namespace std; void myterminate () { cout << "terminate handler called\n"; abort(); // forces…
bjskishore123
  • 6,144
  • 9
  • 44
  • 66
6
votes
1 answer

Can a terminate handler throw an exception?

What is the defined behavior of the following program, if any? #include #include #include void i_throw() { std::cout << "i_throw()" << std::endl; // std::terminate() is noexcept so if the terminate handler…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
3
votes
1 answer

Accessing all uncaught exceptions from terminate handler

I'm currently following C++ core guidelines setting all destructors in my code to be noexcept. Some of my destructors may potentially throw exceptions - in that case I would like the program to crash and provide me with details on what caused the…
smichak
  • 4,716
  • 3
  • 35
  • 47
1
vote
1 answer

How to terminate Python background processes when the calling Bash script is interrupted

I have a Python script (test.py) like the following: try: while True: print("test: {}".format(argv[1])) time.sleep(1) except KeyboardInterrupt: print("process terminated!") So I can stop the program by typing…
A.Yang
  • 21
  • 2
1
vote
2 answers

Questions regarding the usage of set_terminate

I have the below example. (My actual project is a multi-threaded one and I have the terminate handler set for all of them.) I have a couple of questions here. My terminate handler doesn't do anything fancy. It just says that an error occured and…
1
vote
2 answers

catching errors and exiting

In python, is there a way to exit a class after testing a condition, without exiting out of python? Say I have the class class test(): def __init__(self): self.a = 2 def create_b(self): self.b = 3 def…
1
vote
1 answer

terminate all threads or currently running thread keeping the process alive in c++

I want to kill all currently running threads of a process when it receives a stop message. But I want the process to still keep running to accept new requests. I using c++ std::thread and not pthreads
mithu
  • 11
  • 3
0
votes
0 answers

PyQt Progress Bar Update using Thread

I've been writing a program that used a MyWindow(QTableWidget) with a thread. A progress bar is displayed above the sub-window(self.win) displayed as a pop-up. I want a green bar on the status bar to be displayed consecutively, however after…
Happy_win
  • 1
  • 2
0
votes
1 answer

Unhandled exception "terminate called after throwing an instance of" overwrites last line of console

If you throw an unhandled exception out of main like this: #include #include int main() { std::cout << "Hello World 1" << std::endl; throw new std::invalid_argument("A"); return 0; } ... then the process will terminate…
Niko O
  • 406
  • 3
  • 15
0
votes
3 answers

How to catch an error resulting from an invalid memory block being destroyed

The following code makes it so that a destructor is called twice. #include #include #include #include void myterminate() { std::cout << "terminate\n"; abort(); } class data { int a; public: …
Johannes
  • 6,490
  • 10
  • 59
  • 108
-1
votes
1 answer

I can't compile the rest after inputed the age in eclipse, it says "Terminated" on console. Does anyone know how to solve the problem ? Thanks

'What i am trying to do:: Show message based on Good morning (12am-12pm) Good after noon (12pm -4pm) Good evening (4pm to 9pm) Good night ( 9pm to 6am)' import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Scanner; public…
Rafi
  • 1
  • 1
-1
votes
2 answers

How to execute function when software ended with normal close (X) or un expected error thrown

I would like to execute a function when the running application terminated via normal close way (right top X) or un expected error happened and software terminated. How can i do this at c# 4.5 WPF application Thank you
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342