Add and use libclang_error exception class
This commit is contained in:
parent
51f7c3c2b2
commit
a0c2eece5b
3 changed files with 32 additions and 2 deletions
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef CPPAST_LIBCLANG_PARSER_HPP_INCLUDED
|
||||
#define CPPAST_LIBCLANG_PARSER_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <cppast/parser.hpp>
|
||||
|
||||
namespace cppast
|
||||
|
|
@ -53,6 +55,16 @@ namespace cppast
|
|||
friend detail::libclang_compile_config_access;
|
||||
};
|
||||
|
||||
/// The exception thrown when a fatal parse error occurs.
|
||||
class libclang_error final : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/// \effects Creates it with a message.
|
||||
libclang_error(std::string msg) : std::runtime_error(std::move(msg))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// A parser that uses libclang.
|
||||
class libclang_parser final : public parser
|
||||
{
|
||||
|
|
|
|||
|
|
@ -134,7 +134,23 @@ namespace
|
|||
| CXTranslationUnit_KeepGoing, // flags
|
||||
&tu);
|
||||
if (error != CXError_Success)
|
||||
DEBUG_UNREACHABLE(detail::assert_handler{}, "libclang error"); // TODO
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case CXError_Success:
|
||||
DEBUG_UNREACHABLE(detail::assert_handler{});
|
||||
break;
|
||||
|
||||
case CXError_Failure:
|
||||
throw libclang_error("clang_parseTranslationUnit: generic error");
|
||||
case CXError_Crashed:
|
||||
throw libclang_error("clang_parseTranslationUnit: libclang crashed :(");
|
||||
case CXError_InvalidArguments:
|
||||
throw libclang_error("clang_parseTranslationUnit: you shouldn't see this message");
|
||||
case CXError_ASTReadError:
|
||||
throw libclang_error("clang_parseTranslationUnit: AST deserialization error");
|
||||
}
|
||||
}
|
||||
|
||||
return tu;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,9 @@ namespace
|
|||
|
||||
auto exit_code = process.get_exit_status();
|
||||
if (exit_code != 0)
|
||||
DEBUG_UNREACHABLE(detail::assert_handler{}); // TODO: improve error handling
|
||||
throw libclang_error("preprocessor: command '" + cmd
|
||||
+ "' exited with non-zero exit code (" + std::to_string(exit_code)
|
||||
+ ")");
|
||||
|
||||
return preprocessed;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue