Show dialog box for uncaught exception (Windows, lld-link)

Steven Schveighoffer schveiguy at gmail.com
Sun May 5 17:15:10 UTC 2024


On Sunday, 5 May 2024 at 14:55:20 UTC, SimonN wrote:
> My application is a graphical game. I close stdout and stderr 
> by passing `-subsystem:windows` to `lld-link` to suppress the 
> extra console window. For a few fatal errors (missing required 
> resources, can't open display, ...), I throw exceptions, log 
> them to logfile, then re-throw them to crash. I can tell 
> Windows users to look in the logfile, but it would be more 
> fitting on Windows to show an error dialog box in addition to 
> the logging.

```d
int realMain(string[] args)
{
    // all your normal code goes here
}

int main(string[] args)
{
     version(Windows) {
         try {
             realMain(args);
         } catch(Exception e) {
             visualDisplayOfException(e);
             throw e;
         }
     } else {
         // presumably, non-windows systems shouldn't show a 
graphical Exception
         // trace?
         realMain(args);
     }
}
```

-Steve


More information about the Digitalmars-d-learn mailing list