March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | On Wed, 22 Mar 2006 20:42:57 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> "Regan Heath" <regan@netwin.co.nz> wrote in message
> news:ops6uelhqc23k2f5@nrage.netwin.co.nz...
>> Can you catch them all in WinMain i.e.
>>
>> try {
>> ..main..
>> } catch(Object o) {
>> MessageBox(...
>> }
>
> If I use the method proposed by Sean, I'd have to catch the exceptions in my
> own main function, as the dmain catches them and prints them to the console.
> i.e.
>
> extern(C) main(..)
>
> int WinMain(..)
> {
> return main(1, &cmdline);
> }
>
> void main()
> {
> try
> {
> crap
> }
> catch(Exception e)
> {
> MessageBox("oh man" ~ e.toString());
> }
> }
>
> Pretty ugly.
Yeah, though if you add 1 more layer, i.e.
extern(C) main(..)
int WinMain(..)
{
return main(1, &cmdline);
}
void main()
{
try
{
real_main();
}
catch(Exception e)
{
MessageBox("oh man" ~ e.toString());
}
}
void real_main()
{
..crap..
}
it's not so bad.
Regan
|
March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | "kris" <foo@bar.com> wrote in message news:dvsum5$2du4$1@digitaldaemon.com... > You might ask Sean to decouple the default exception-handler from the runtime support in Ares. The idea would be that you could provide your own default-handler, and then the linker would bind that instead. Sean is already doing a lot of things like that with Ares, so it may not be too much of a stretch. Not using Ares, sorry. |
March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | "Hasan Aljudy" <hasan.aljudy@gmail.com> wrote in message news:dvsvif$2f4p$1@digitaldaemon.com... > I think you can use the new scope(failure) construct! I had a fleeting thought about that, then realized that scope(failure) doesn't let you actually catch the offending exception. |
March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | "Regan Heath" <regan@netwin.co.nz> wrote in message news:ops6uf9kzv23k2f5@nrage.netwin.co.nz... > Yeah, though if you add 1 more layer, i.e. > it's not so bad. Well then.. :) |
March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> "Chris Miller" <chris@dprogramming.com> wrote in message news:op.s6uctr1mpo9bzi@moe...
>> Can just use GetModuleHandleA(null)
>
> Why thank you. I was wondering if there was an API call to get that.
>
> Now the only problem is that exceptions are displayed on the command line instead of popping up.. which may be a problem for the other programmers in my little group..
Why not catch all exceptions in main, display them as appropriate, and then rethrow:
void main( char[][] args ) {
try {
...
}
catch( Exception e ) {
// display dialog
throw e;
}
catch( Object o ) {
// display dialog
}
}
Passing exceptions completely through the runtime would be a bit weird, as by the time the exception reached WinMain module dtors would have been called, the GC would have been terminated, etc.
Sean
|
March 23, 2006 Re: make D windows-aware | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | "Sean Kelly" <sean@f4.ca> wrote in message news:dvt5j1$2n35$1@digitaldaemon.com... > Why not catch all exceptions in main, display them as appropriate, and then rethrow: Because that's ugly ;) Seriously, though, I'm working with some more novice programmers, and I want to make this as easy as possible for them. So I'd like to be able to say "just put everything in this function and don't worry about it." I think the extra layer of main like Regan suggested is what I'll do. > Passing exceptions completely through the runtime would be a bit weird, as by the time the exception reached WinMain module dtors would have been called, the GC would have been terminated, etc. They'd never make it all the way back to WinMain; they get caught by dmain and printed to the console. It's a consequence of dmain being meant for console apps. |
Copyright © 1999-2021 by the D Language Foundation