#include <iostream>
#include <exception>
#include <string>
int main()
{
try
{
std::string s;
s.resize(-1);
//throw std::runtime_error("Bad thing happended"); // 직접 던질수도 있다.
//throw CustomException();
}
catch(std::length_error & exception) // exception의 자식클래스인 length error로 잡을 수 있다.
{
std::cerr << "Length_Error" << "\n";
std::cerr << excpetion.what() << "\n";
}
catch(std::exception & exception)
{
// std::cout << typeid(exception).name() << "\n"; // length error
std::cerr << exception.what() << "\n"; // 문자열로 에러를 출력 // "string too long"
}
return 0;
}