Skip to content

Instantly share code, notes, and snippets.

@DSCF-1224
Last active October 23, 2019 22:07
Show Gist options
  • Save DSCF-1224/fc6abe855a9b336bc050b50282654d0e to your computer and use it in GitHub Desktop.
Save DSCF-1224/fc6abe855a9b336bc050b50282654d0e to your computer and use it in GitHub Desktop.
my handling exceptions for C++
#include <cstdlib>
// for; EXIT_SUCCESS
// for; EXIT_FAILURE
#include <iostream>
// for; std::cerr
#include <string>
// for; std::string
// for; std::string std::literals::string_literals::operator ""s
#include "ver20191023_01.hpp"
using namespace std::literals;
int main()
{
int i;
try
{
i = std::stoi("hoge");
}
catch (const std::invalid_argument &e)
{
std::cout << my_handling_exceptions::stoi(e);
}
catch (const std::out_of_range &e)
{
std::cout << my_handling_exceptions::stoi(e);
}
std::cout << i << "\n"s;
try
{
i = std::stoi("999999999999999999999999999999");
}
catch (const std::invalid_argument &e)
{
std::cout << my_handling_exceptions::stoi(e);
}
catch (const std::out_of_range &e)
{
std::cout << my_handling_exceptions::stoi(e);
}
std::cout << i << "\n"s;
return EXIT_SUCCESS;
}
/* EOF */
#include <cstdlib>
// for; EXIT_FAILURE
#include <iostream>
// for; std::cerr
#include <string>
// for; std::string
// for; std::string std::literals::string_literals::operator ""s
#include <stdexcept>
// for; std::invalid_argument
// for; std::out_of_range
using namespace std::literals;
namespace my_handling_exceptions
{
std::string message_func(const std::string &name_function)
{
return "Function `"s + name_function + "` throw the error !"s + "\n"s;
}
std::string message_throw(const std::string &name_class)
{
return "`"s + name_class + "` error was thrown."s + "\n"s;
}
std::string message_throw(const std::invalid_argument &e)
{
return message_throw("invalid_argument"s);
}
std::string message_throw(const std::out_of_range &e)
{
return message_throw("out_of_range"s);
}
std::string stoi()
{
return message_func("stoi"s);
}
std::string stoi(const std::invalid_argument &e)
{
return stoi() + message_throw(e);
}
std::string stoi(const std::out_of_range &e)
{
return stoi() + message_throw(e);
}
} // namespace my_handling_exceptions
/* EOF */
# STEP.01
# 当該PS1ファイルの絶対パスを取得する
$path_file_ThisPS1 = $MyInvocation.MyCommand.Path
# STEP.02
# 取得した当該PS1ファイルの絶対パスから,
# 同PS1ファイルが存在するフォルダのパスを取得する
$path_fldr_ThisPS1 = Split-Path -Parent $path_file_ThisPS1
# STEP.03
# 当該PS1ファイルが存在するフォルダをカレント ディレクトリに指定する
Set-Location $path_fldr_ThisPS1
g++ -std=c++17 -Wall -pedantic-errors -o ver20191023_01.exe ver20191023_01.cpp
<# EOF #>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment