DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
fatalException.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: fatalException.hpp
5// Author: crdrisko
6// Date: 04/07/2020-11:09:24
7// Description: Defines a specialized exception handling class designed around the error utilities
8
9#ifndef DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_ERRORS_EXCEPTIONS_FATALEXCEPTION_HPP
10#define DRYCHEM_COMMON_UTILITIES_INCLUDE_COMMON_UTILS_ERRORS_EXCEPTIONS_FATALEXCEPTION_HPP
11
12#include <exception>
13#include <sstream>
14#include <string>
15
18
20{
27 class FatalException : public std::exception
28 {
29 private:
31
32 const char* what() const noexcept override { return error.message.c_str(); }
33
34 public:
35 explicit FatalException(const ErrorMessage& error_) : error {error_}
36 {
37 if (!error.fileName.empty() && error.lineNumber != 0ul)
38 {
39 std::stringstream errorMessage;
40
41 errorMessage << '(' << error.fileName.substr(error.fileName.find_last_of('/') + 1, error.fileName.length())
42 << ": " << std::to_string(error.lineNumber) << ")\n\t" << error.message;
43
44 error.message = errorMessage.str();
45 }
46 }
47
50 };
51} // namespace CppUtils::Errors
52
53#endif
ErrorMessage error
Definition fatalException.hpp:30
FatalException(const ErrorMessage &error_)
Definition fatalException.hpp:35
void handleErrorWithMessage() const
Delegate our exception handling to the error handling classes.
Definition fatalException.hpp:49
const char * what() const noexcept override
Definition fatalException.hpp:32
Definition fatalException.hpp:20
auto printFatalErrorMessage
A convenience function for printing an error message when said error is fatal.
Definition errorHandling.hpp:49
Definition errorTypes.hpp:32