From 218f6eacb1c74a31280884f0afd64ef350e1094c Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 24 Sep 2024 04:49:29 +0200 Subject: [PATCH] destructor error handling got more thorough analysis... --- BASED.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/BASED.md b/BASED.md index ad0ab57..98e3169 100644 --- a/BASED.md +++ b/BASED.md @@ -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!