Jump to page: 1 2 3
Thread overview
Conclusions of the exception discussion
Feb 25, 2012
Jonathan M Davis
Feb 25, 2012
Daniel Murphy
Feb 25, 2012
Jonathan M Davis
Feb 25, 2012
Daniel Murphy
Feb 25, 2012
Jonathan M Davis
Feb 25, 2012
deadalnix
Feb 25, 2012
Daniel Murphy
Feb 25, 2012
deadalnix
Feb 26, 2012
Daniel Murphy
Feb 25, 2012
kennytm
Feb 26, 2012
Daniel Murphy
Feb 25, 2012
Kevin Cox
Feb 25, 2012
Daniel Murphy
Feb 25, 2012
Martin Nowak
Feb 25, 2012
Daniel Murphy
Feb 25, 2012
Jonathan M Davis
Feb 26, 2012
Kagamin
Feb 26, 2012
Jonathan M Davis
Feb 25, 2012
Johannes Pfau
Feb 25, 2012
Jonathan M Davis
Feb 25, 2012
deadalnix
Feb 26, 2012
Piotr Szturmaj
Feb 26, 2012
Timon Gehr
Feb 26, 2012
Piotr Szturmaj
Feb 26, 2012
bearophile
Mar 02, 2012
Don
February 25, 2012
Okay, the "The Right Approach to Exceptions" thread is a huge, confusing mess at this point without a clear, definitive conclusion, and we need one. So, I'm posting here, in a new thread, what appears to me to be the conclusion that that thread comes to and see if we can get some sort of consensus on this.

There are three things that that thread appears to conclude that we should do to improve the current situation with exceptions in Phobos and in D in general:

1. Phobos' exceptions should be reorganized into a class hierarchy designed such that the exceptions can be reusable outside of Phobos. We will no longer follow the policy of an exception per modules. A module may declare 0 to many exceptions depending on the problems that it would be reporting by throwing exceptions, and some modules will reuse the exceptions from other modules where appropriate.

The exact set of exceptions that we're going to end up with and how the hierarchy will be laid out has yet to be determined. It may or may not be similar to what Java and C# have. We will probably look at what they have as examples but will do whatever we decide works best for D and Phobos, and that may or may not have any relation to what those languages do. This will likely start with a minimal number of exceptions and will grow as necessary rather than trying to create a lot of exception types up front which we may not ever need. Regardless, we may know that we want a hierarchy, but the exact hierarchy has yet to be determined.


2. We should add a feature to the language to make it possible to catch multiple exception types with a single catch statement. There are two suggestions.

A. Do something similar to what Java 7 is doing and make it possible to simply list the exceptions that a particular catch statement accepts. That catch block will then catch any of the matching exceptions, and the type of the variable will be their most derived common type. One possible syntax would be

catch(e : Ex1, Ex2, Ex3) {}

B. Make it possible to add a condition which would be run when the catch statements are processed to allow you to catch based on other stuff in addition to the type. The condition would be a condition run at runtime rather than a compile time condition like template constraints. e.g.

catch(MyException e) if(e.prop == value) {}

It is unclear which we want to do or whether we want to do both. So, that still needs to be discussed further. But it's fairly clear that the majority want a feature along the lines of one or both of those two suggestions. However, regardless of which we choose, someone is going to have to take the time to implement it, since odds are that Walter isn't going to do it. So, whether we end up with a feature along these lines is highly dependent on whether anyone is willing to take the time to implement it and get it accepted by Walter.


3. We should add a Variant[string] property to Exception. Every derived class will then populate it with the values of its member variables in their constructors, and code outside of the exception classes can choose to insert other values into the table which are useful for the particular programs that they're in but which don't make sense to put in the exception types themselves.

A free function will then be designed and implemented which will take some kind of format string along with an exception and will then allow you to generate a message from that exception using whatever formatting you want using the hash table to generically obtain the values from the exception without needing to catch or know the exact type of the exception. e.g.

catch(Exception e)
{
    writeln(magicFormattingFunction(formatStr, e));
}

This Variant[string] property would _not_ replace having direct member variables in derived exceptions. Rather, it would allow us to make sure that we only put member variables in derived exceptions when they belong there, and code which wants additional data but not a new exception type can use the hash table to hold it. And of course, it also gives us the foundation to build the fancier string formatting capabalities.


There were other ideas that were discussed in the thread, but I think that these are the ones that we have at least some consensus on. However, given the mess that thread is, we really should make it clear in a separate thread (this thread) that we have a consensus that these are indeed the things that we want to pursue to improve exceptions in D and Phobos. Thoughts? Opinions?

- Jonathan M Davis
February 25, 2012
"Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.93.1330149312.24984.digitalmars-d@puremagic.com...
> However, regardless of which we choose, someone is going to have to take
> the
> time to implement it, since odds are that Walter isn't going to do it. So,
> whether we end up with a feature along these lines is highly dependent on
> whether anyone is willing to take the time to implement it and get it
> accepted
> by Walter.

Waaaay ahead of you here.

https://github.com/D-Programming-Language/dmd/pull/738

It's currently 'catch(auto e : E1, E2, E3)' but changing the syntax is trivial if everyone decides they want it.


February 25, 2012
On Saturday, February 25, 2012 17:26:02 Daniel Murphy wrote:
> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.93.1330149312.24984.digitalmars-d@puremagic.com...
> 
> > However, regardless of which we choose, someone is going to have to take
> > the
> > time to implement it, since odds are that Walter isn't going to do it. So,
> > whether we end up with a feature along these lines is highly dependent on
> > whether anyone is willing to take the time to implement it and get it
> > accepted
> > by Walter.
> 
> Waaaay ahead of you here.
> 
> https://github.com/D-Programming-Language/dmd/pull/738
> 
> It's currently 'catch(auto e : E1, E2, E3)' but changing the syntax is trivial if everyone decides they want it.

Whoa. Are trying to be the next Kenji Hara? ;)

It's definitely nice to have some solid, prolific contributors to the compiler.

- Jonathan M Davis
February 25, 2012
Am Fri, 24 Feb 2012 21:53:47 -0800
schrieb Jonathan M Davis <jmdavisProg@gmx.com>:

> There were other ideas that were discussed in the thread, but I think that these are the ones that we have at least some consensus on. However, given the mess that thread is, we really should make it clear in a separate thread (this thread) that we have a consensus that these are indeed the things that we want to pursue to improve exceptions in D and Phobos. Thoughts? Opinions?
> 
> - Jonathan M Davis

What about that lisp exception/recovery idea? That was the most interesting idea imho.
February 25, 2012
On Saturday, February 25, 2012 10:11:56 Johannes Pfau wrote:
> Am Fri, 24 Feb 2012 21:53:47 -0800
> 
> schrieb Jonathan M Davis <jmdavisProg@gmx.com>:
> > There were other ideas that were discussed in the thread, but I think that these are the ones that we have at least some consensus on. However, given the mess that thread is, we really should make it clear in a separate thread (this thread) that we have a consensus that these are indeed the things that we want to pursue to improve exceptions in D and Phobos. Thoughts? Opinions?
> > 
> > - Jonathan M Davis
> 
> What about that lisp exception/recovery idea? That was the most interesting idea imho.

There's no consensus whatsoever on using that.  It's just a new, interesting idea at this point, and it's incredibly experimental. Some folks are playing around with it right now, but until they've ironed it out, there's not much point in discussing whether we should add it to Phobos IMHO. It's also something that we can add on top of the current exception scheme at a later date, so we don't have to do anything with it now. We'll have to give it more bake time before we make any decisions about it. And I believe that the main proponents of it agree with that assessment.

- Jonathan M Davis
February 25, 2012
"Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.94.1330151556.24984.digitalmars-d@puremagic.com...
> On Saturday, February 25, 2012 17:26:02 Daniel Murphy wrote:
>> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.93.1330149312.24984.digitalmars-d@puremagic.com...
>>
>> > However, regardless of which we choose, someone is going to have to
>> > take
>> > the
>> > time to implement it, since odds are that Walter isn't going to do it.
>> > So,
>> > whether we end up with a feature along these lines is highly dependent
>> > on
>> > whether anyone is willing to take the time to implement it and get it
>> > accepted
>> > by Walter.
>>
>> Waaaay ahead of you here.
>>
>> https://github.com/D-Programming-Language/dmd/pull/738
>>
>> It's currently 'catch(auto e : E1, E2, E3)' but changing the syntax is trivial if everyone decides they want it.
>
> Whoa. Are trying to be the next Kenji Hara? ;)
>
> It's definitely nice to have some solid, prolific contributors to the compiler.
>
> - Jonathan M Davis

Lol I've been around for a while.


February 25, 2012
On Saturday, February 25, 2012 21:12:51 Daniel Murphy wrote:
> Lol I've been around for a while.

I know. But particularly over the last few months, you seem to be doing a lot.

 - Jonathan M Davis
February 25, 2012
Le 25/02/2012 07:26, Daniel Murphy a écrit :
> "Jonathan M Davis"<jmdavisProg@gmx.com>  wrote in message
> news:mailman.93.1330149312.24984.digitalmars-d@puremagic.com...
>> However, regardless of which we choose, someone is going to have to take
>> the
>> time to implement it, since odds are that Walter isn't going to do it. So,
>> whether we end up with a feature along these lines is highly dependent on
>> whether anyone is willing to take the time to implement it and get it
>> accepted
>> by Walter.
>
> Waaaay ahead of you here.
>
> https://github.com/D-Programming-Language/dmd/pull/738
>
> It's currently 'catch(auto e : E1, E2, E3)' but changing the syntax is
> trivial if everyone decides they want it.
>
>

I do think this approach have a flaw. If we go in that direction, then it push devs to create new Exception type just to catch them, because this is the only way we have.

If I understand properly your pull request, the compiler will be duplicating catch block ? If it is the case, would it be possible to use static if to use type specific stuff of E1, E2 or E3, depending on which one we are facing ?

BTW, great job, it is definitively a nice addition to have.

jmdavis > good job to synthetize all this. I think you get the most importants points of the talk.
February 25, 2012
Le 25/02/2012 10:11, Johannes Pfau a écrit :
> Am Fri, 24 Feb 2012 21:53:47 -0800
> schrieb Jonathan M Davis<jmdavisProg@gmx.com>:
>
>> There were other ideas that were discussed in the thread, but I think
>> that these are the ones that we have at least some consensus on.
>> However, given the mess that thread is, we really should make it
>> clear in a separate thread (this thread) that we have a consensus
>> that these are indeed the things that we want to pursue to improve
>> exceptions in D and Phobos. Thoughts? Opinions?
>>
>> - Jonathan M Davis
>
> What about that lisp exception/recovery idea? That was the most
> interesting idea imho.

This idea is very interesting, but we must separate it from the Exception issue. For separation of concerns, let's build this on top of the Exception system.
February 25, 2012
I think there should also be multiple catches so that you can deal with
different exceptions different ways without trying to upcast them over and
over again.
On Feb 25, 2012 1:30 AM, "Daniel Murphy" <yebblies@nospamgmail.com> wrote:

> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message news:mailman.93.1330149312.24984.digitalmars-d@puremagic.com...
> > However, regardless of which we choose, someone is going to have to take
> > the
> > time to implement it, since odds are that Walter isn't going to do it.
> So,
> > whether we end up with a feature along these lines is highly dependent on
> > whether anyone is willing to take the time to implement it and get it
> > accepted
> > by Walter.
>
> Waaaay ahead of you here.
>
> https://github.com/D-Programming-Language/dmd/pull/738
>
> It's currently 'catch(auto e : E1, E2, E3)' but changing the syntax is trivial if everyone decides they want it.
>
>
>


« First   ‹ Prev
1 2 3