Description
This feature is based on https://youtu.be/ARYP83yNAWk?t=2227
Long time ago I wrote to you an email about it, but it was lost somewhere in history of civilisation ...
Anyway, I just want to extend your idea to use value based exceptions like it is done in Rust for example with Result<,>
class and ?
syntax
See the code:
run: (file: &std::string) -> int32_t throws Error1, Error2 {
file := File::open(file).try;
contents := std::string{};
file.read_to_string(contents&).try;
return contents.trim().parse().try;
}
This function could throw 2 exceptions Error1 or Error2.
Implementation could be done using union
and value for describing type of error.
See godbolt possible underlying implementation: https://godbolt.org/z/a_vbNw
I suggest to convert all functions without throws
keyword ( in cpp2 syntax) to function with noexcept
(in C++ current syntax)
Also a list of exceptions could be generated automatically by analyzing which new cpp2 syntax functions is called from current context:
run: (file: &std::string) -> int32_t throws {
file := File::open(file).try;
contents := std::string{};
file.read_to_string(contents&).try;
return contents.trim().parse().try;
}
could be converted to:
run: (file: &std::string) -> int32_t throws Error1, Error2 {
file := File::open(file).try;
contents := std::string{};
file.read_to_string(contents&).try;
return contents.trim().parse().try;
}
Because cpp2 compiler knows that , for example, File::open(file).try
and file.read_to_string(contents&).try
could throw Error1
or Error2