DigestCPP

Lets Understand With Example

  • Home
  • Design Principal
  • Design Patterns
  • C++ 11 Features
  • C++11 Multithreading
  • Contact Us

noexcept c++11

noexcept

It is keyword in c++11 and it used with functions only and that guarantee that they will not emit exception(or can not throw exception). we can say in other words that function is NOT meant for throwing exception.  Example

void fun1() noexcept;

What will happen if function with noexcept throw exception ?

Program will be terminated, you can see below example std::terminate is called.

Source code with example:

//Header file
#include<iostream>

void fun01() noexcept
{
    std::cout<<"fun01"<<std::endl;
}

void fun02() noexcept
{
    std::cout<<"fun02"<<std::endl;
    throw;
}


int main()
{
    std::cout<<"noexcept"<<std::endl;
    fun01();
    fun02();
    return 0;
}

Output:

noexcept
fun01
fun02
terminate called without an active exception
Aborted (core dumped)

Primary Sidebar




DigestCPP © 2023. All rights reserved.

    About Privacy Policy Terms and Conditions Contact Us Disclaimer