Answers for "cpp exception"

3

throw exception c++

#include <stdexcept>
#include <limits>
#include <iostream>

using namespace std;

void MyFunc(int c)
{
    if (c > numeric_limits< char> ::max())
        throw invalid_argument("MyFunc argument too large.");
    //...
}
Posted by: Guest on November-02-2020
14

python exception

try:
  # code block
except ValueError as ve:
  print(ve)
Posted by: Guest on March-31-2020
6

c++ try

try {
	//do
} catch (...){
	//if error do
}
Posted by: Guest on March-02-2020
1

exception handling c++

// exceptions
#include <iostream>
using namespace std;

int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << 'n';
  }
  return 0;
}
Posted by: Guest on July-13-2020
0

cpp get exception type

#include <iostream>
#include <cxxabi.h>

const char* currentExceptionTypeName()
{
    int status;
    return abi::__cxa_demangle(abi::__cxa_current_exception_type()->name(), 0, 0, &status);
}

int main()
{
    try {
        throw std::string();
    } catch (...) {
        std::cout<<"Type of caught exception is "<<currentExceptionTypeName()<<std::endl;
    }

    return 0;
}
Posted by: Guest on July-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language