CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Ketan Lalcheta
#include <iostream>
#include <thread>
using namespace std;
void operations_1()
{
}
void operations_2()
{
throw (new runtime_error("my mood..!"));
}
void uglyWayOfThread()
{
thread t1(operations_1);
//not joining thread will crash
//we can't join directly here as it will block the other operations till thread is not over
//as next operation might throw exception, we have to join thread in both try and catch
//this becomes tedious when code is large
//hence follow RAII on thread as well
try
{
operations_2();
if(t1.joinable())
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run