Try/Catch with version condition

foo email at example.org
Tue Apr 9 14:43:54 UTC 2019


How would I get this to work:

---
version(foo) {
     try {
}
throw new Exception("This should only be fatal when the version 
is not 'foo'.");
version(foo) {
     } catch (Exception e) {
         import std.stdio;
         writeln(e);
     }
}
---

The only way I could think of to get this to work would be:
---
version(foo) {
     try {
         throw new Exception("This should only be fatal when the 
version is not 'foo'.");
     } catch (Exception e) {
         import std.stdio;
         writeln(e);
     }
} else {
     throw new Exception("This should only be fatal when the 
version is not 'foo'.");
}
---

But then that requires too much code duplication.
What would be the best way to do this?


More information about the Digitalmars-d mailing list