implement exception handling in some complicated cases
This commit is contained in:
parent
d6a9c62a63
commit
46ddb16128
@ -8,11 +8,6 @@
|
||||
|
||||
namespace nf7 {
|
||||
|
||||
class LifeExpiredException final : public nf7::Exception {
|
||||
public:
|
||||
using nf7::Exception::Exception;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Life final {
|
||||
public:
|
||||
@ -57,7 +52,7 @@ class Life<T>::Ref final {
|
||||
|
||||
void EnforceAlive() const {
|
||||
if (!data_->ptr) {
|
||||
throw LifeExpiredException {"target expired"};
|
||||
throw nf7::ExpiredException {"target expired"};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ class InlineNode::Lambda final : public nf7::Node::Lambda,
|
||||
th->Resume(thL, 3);
|
||||
});
|
||||
|
||||
} catch (nf7::LifeExpiredException&) {
|
||||
} catch (nf7::ExpiredException&) {
|
||||
} catch (nf7::Exception& e) {
|
||||
log_->Error(e.msg());
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ class Node::Lambda final : public nf7::Node::Lambda,
|
||||
log_->Error("failed to call lua function: "+e.msg());
|
||||
}
|
||||
});
|
||||
} catch (nf7::LifeExpiredException&) {
|
||||
} catch (nf7::ExpiredException&) {
|
||||
} catch (nf7::Exception& e) {
|
||||
log_->Error(e.msg());
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ try {
|
||||
ssla_ = nullptr;
|
||||
la_ = nullptr;
|
||||
}
|
||||
} catch (nf7::LifeExpiredException&) {
|
||||
} catch (nf7::ExpiredException&) {
|
||||
ss->Finish();
|
||||
} catch (nf7::FileHolder::EmptyException&) {
|
||||
ss->Finish();
|
||||
|
4
main.cc
4
main.cc
@ -97,7 +97,7 @@ class Env final : public nf7::Env {
|
||||
|
||||
// trigger global watcher
|
||||
for (auto w : watchers_map_[0]) w->Handle(e);
|
||||
} catch (ExpiredException&) {
|
||||
} catch (nf7::ExpiredException&) {
|
||||
}
|
||||
|
||||
void Exit() noexcept override {
|
||||
@ -105,7 +105,7 @@ class Env final : public nf7::Env {
|
||||
}
|
||||
void Save() noexcept override {
|
||||
try {
|
||||
nf7::Serializer::Save(kFileName, root_);
|
||||
nf7::Serializer::Save(*this, kFileName, root_);
|
||||
} catch (nf7::Exception&) {
|
||||
Panic();
|
||||
}
|
||||
|
4
nf7.cc
4
nf7.cc
@ -293,7 +293,7 @@ Serializer::ChunkGuard::~ChunkGuard() noexcept {
|
||||
*ar_ & static_cast<uint64_t>(end - begin_);
|
||||
ar_->st_->Seek(end);
|
||||
} catch (nf7::Exception&) {
|
||||
// TODO
|
||||
ar_->env_->Throw(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ Deserializer::ChunkGuard::~ChunkGuard() {
|
||||
ar_->st_->Seek(end);
|
||||
}
|
||||
} catch (nf7::Exception&) {
|
||||
// TODO
|
||||
ar_->env_->Throw(std::current_exception());
|
||||
}
|
||||
}
|
||||
void Deserializer::ChunkGuard::ValidateEnd() {
|
||||
|
9
nf7.hh
9
nf7.hh
@ -383,14 +383,14 @@ class Serializer final :
|
||||
size_t begin_;
|
||||
};
|
||||
|
||||
static void Save(const char* path, auto& v) {
|
||||
static void Save(nf7::Env& env, const char* path, auto& v) {
|
||||
SerializerStream st {path, "wb"};
|
||||
Serializer ar {st};
|
||||
Serializer ar {env, st};
|
||||
ar(v);
|
||||
}
|
||||
|
||||
Serializer(nf7::SerializerStream& st) :
|
||||
binary_ostream(st), oarchive_header(st), st_(&st) {
|
||||
Serializer(nf7::Env& env, nf7::SerializerStream& st) :
|
||||
binary_ostream(st), oarchive_header(st), env_(&env), st_(&st) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -413,6 +413,7 @@ class Serializer final :
|
||||
}
|
||||
|
||||
private:
|
||||
nf7::Env* const env_;
|
||||
nf7::SerializerStream* const st_;
|
||||
};
|
||||
class Deserializer final :
|
||||
|
Loading…
x
Reference in New Issue
Block a user