Try/Catch with version condition
Bastiaan Veelo
Bastiaan at Veelo.net
Tue Apr 9 16:54:19 UTC 2019
On Tuesday, 9 April 2019 at 14:56:03 UTC, Julian wrote:
> Something like this maybe?
>
> import std.stdio;
>
> void main() {
> try {
> throw new Exception("fatal for non-foo versions");
> } catch (Exception e) {
> version(foo) {
> writeln(e);
> } else {
> throw(e);
> }
> }
> writeln("continuing, probably in version foo");
> }
Beware though that exception handling is not typically
performant. From the spec[1]:
> - Errors are not part of the normal flow of a program. Errors
> are exceptional, unusual, and unexpected.
> - Because errors are unusual, execution of error handling code
> is not performance critical.
[1]
https://dlang.org/spec/errors.html#the_d_error_handling_solution
More information about the Digitalmars-d
mailing list