2015-08-18 00:23:10 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "kernel/kernel_exception.h"
|
2015-09-09 00:45:36 +00:00
|
|
|
#include "library/unifier.h"
|
|
|
|
#include "library/tactic/tactic.h"
|
2015-08-18 00:23:10 +00:00
|
|
|
#include "api/exception.h"
|
|
|
|
#include "api/string.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
memout_exception * get_memout_exception() {
|
|
|
|
static memout_exception g_memout;
|
|
|
|
return &g_memout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_nonnull(void const * ptr) {
|
|
|
|
if (!ptr)
|
|
|
|
throw exception("invalid argument, it must be a nonnull pointer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 18:01:46 +00:00
|
|
|
void lean_exception_del(lean_exception e) {
|
2015-08-18 00:23:10 +00:00
|
|
|
lean::throwable * t = lean::to_exception(e);
|
|
|
|
if (t != lean::get_memout_exception()) {
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 18:01:46 +00:00
|
|
|
char const * lean_exception_get_message(lean_exception e) {
|
2015-08-18 00:23:10 +00:00
|
|
|
if (!e)
|
|
|
|
return 0;
|
|
|
|
try {
|
|
|
|
return lean::mk_string(lean::to_exception(e)->what());
|
|
|
|
} catch (...) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 18:01:46 +00:00
|
|
|
lean_exception_kind lean_exception_get_kind(lean_exception e) {
|
2015-08-18 00:23:10 +00:00
|
|
|
lean::throwable * ex = lean::to_exception(e);
|
|
|
|
if (!ex)
|
|
|
|
return LEAN_NULL_EXCEPTION;
|
|
|
|
if (dynamic_cast<lean::memout_exception*>(ex))
|
|
|
|
return LEAN_OUT_OF_MEMORY;
|
|
|
|
if (dynamic_cast<lean::system_exception*>(ex))
|
|
|
|
return LEAN_SYSTEM_EXCEPTION;
|
|
|
|
if (dynamic_cast<lean::kernel_exception*>(ex))
|
|
|
|
return LEAN_KERNEL_EXCEPTION;
|
|
|
|
if (dynamic_cast<lean::interrupted*>(ex))
|
|
|
|
return LEAN_INTERRUPTED;
|
2015-09-09 00:45:36 +00:00
|
|
|
if (dynamic_cast<lean::unifier_exception*>(ex))
|
|
|
|
return LEAN_UNIFIER_EXCEPTION;
|
|
|
|
if (dynamic_cast<lean::tactic_exception*>(ex))
|
|
|
|
return LEAN_TACTIC_EXCEPTION;
|
|
|
|
if (dynamic_cast<lean::parser_exception*>(ex))
|
|
|
|
return LEAN_PARSER_EXCEPTION;
|
2015-08-18 00:23:10 +00:00
|
|
|
return LEAN_OTHER_EXCEPTION;
|
|
|
|
}
|