destructor error handling got more thorough analysis...

This commit is contained in:
Richard Thier 2024-09-24 04:49:29 +02:00
parent 9212dfc814
commit 218f6eacb1

View File

@ -928,11 +928,11 @@ A legjobb egy Zig-szerű megoldás lenne - jelenleg ezt mondanám a választáso
void testcode() {
// onfail clause is mandatory if function declaration has an onfail - unlike with exceptions
// Its "errors as values" philosophy and implemented via record returns / double return values.
FileHandle h = open_file("help.txt") onfail(err) {
FileHandle h = open_file("help.txt") onfail(DatabaseError err) {
// Must handle all of the cases (or have a "default"?)
NOT_FOUND:
// Can chain, and have visibility for variables in the main expression (here: h)
h = open_file("secondary_help.txt") onfail(err2) {
h = open_file("secondary_help.txt") onfail(DatabaseConnection err2) {
default:
printf("help.txt not found and secondary_help.txt errs with: %s\n", err2.msg());
}
@ -970,7 +970,19 @@ FONTOS (destruktor error):
DatabaseConnection dc;
dc.insert(...);
dc.commit();
} onfail(err) {
DatabaseConnection dc2;
dc2.insert(...);
dc2.commit();
SocketConnection sc;
sc.insert(...);
sc.commit();
} onfail(DatabaseError dc.err) { // TODO: Jó-e a syntax? Itt a dc adja meg minek a dekonstruktora futott (elhagyható)
CannotClose:
...
} onfail(DatabaseError dc2.err) {
CannotClose:
...
} onfail(SocketError err) {
CannotClose:
...
}
@ -978,6 +990,8 @@ FONTOS (destruktor error):
Megjegyzés: A scope végére helyezett onfail talán kiválthatná a lokálisat / függvényhívás pontján lévőt?
Ekkor talán javasolt lenne a scope-osnál a teljes típust kiírni, mert többféle tagged enum lehet?
Megjegyzés: thread_local-ba tehet mondjuk error esetén void* plusz adatot az error kiváltó kód (ha kell). (szabvány v egyedi?)
FONTOS:
A fentieknek működnie kell konstruktor esetén is (destruktornál viszont semmiképp). Gondolj bele: az kell a RAII-hoz!