October 23, 2005
Thanks heaps for your answers, Sean and John. I'm not sure I understand everything that you say, but my main questions are answered. I guess I will re-read your posts, test it on my computer, and someday I'll get the remainder. ;-)

Thanks again,
Mathias


October 23, 2005
On Sat, 22 Oct 2005 12:12:27 +0200, Mathias <Mathias_member@pathlink.com> wrote:

> Ah, I think I'm beginning to understand... ;-) I was confused by the line:
>
> # catch(Exception e)
>
> and what it does. I didn't understand why I couldn't simply write:
>
> # catch(e)
>
> I think the correct answer is that the compiler simply doesn't know what "e" is
> since it is created in another function. The fact that the throwing function
> knows what kind of object it throws doesn't change this.
> "catch(e)" just tells the compiler "catch something called 'e'", and the
> compiler replies: "I can't do anything unless I know what kind of data 'e' is."
> "catch (Exception e)" tells the compiler "catch an Exception object that we call
> 'e' here" and the compiler says "O.K."
> If both throw and catch were located within the same function, I could indeed
> simply write catch(e).
> I hope this is correct now. (If not, please tell me so.)

Yes, but no. <g> I see that you "hear the bell but don't know in which church does it ring". :)

1. Languages with "strong typing" (i'm not sure is this right term) have to know of which type is every used variable before they'll use it. They just have to reserve fixed amount of bytes first. And they have to know what you can do with such variable, and what you can not.

This is one and you seem to get it.

2. But there is another reason too:
You can have many "catch" clauses, and you have to tell the compiler which type of throwed object you want to handle. That it why even in PHP (where variables may be one time strings and another something else) you have to specify what do you want to handle. In folowing example you can do "something completly diffrent" if assercion failed and "something completly diffrent" if other type of exception was throwed.

try {
 ...
} catch (AssertException a) {
 writef("Assert");
} catch (Exception e) {
 writef("other exception");
}

That is why even if throw and catch would be in same function you have to add type first. They could be just many throws in such function and each of them could throw diffrent things.

I do not wish you to turn you off using this group (as you can see many helpful people are here), but I think you should propably find some good book/web resource to learn faster about standard programing concepts like exceptions. D is very similar to C++ in many concepts so don't be afraid to use C++ examples (there is much more of them in the moment). What you have to keep in mind (dealing with exceptions in D, knowing how they work in C++) is that Objects in D are allways passed by reference (no copying is ever made, only handlers are passed) and of course D has neat "finally" keyword.

Regards,
-- 
Dawid Ciężarkiewicz
October 24, 2005
In article <op.sy4c2qee58xlqs@localhost.localdomain>, =?utf-8?B?RGF3aWQgQ2nEmcW8YXJraWV3aWN6?= says...

>I do not wish you to turn you off using this group (as you can see many helpful people are here), but I think you should propably find some good book/web resource to learn faster about standard programing concepts like exceptions. D is very similar to C++ in many concepts so don't be afraid to use C++ examples (there is much more of them in the moment). What you have to keep in mind (dealing with exceptions in D, knowing how they work in C++) is that Objects in D are allways passed by reference (no copying is ever made, only handlers are passed) and of course D has neat "finally" keyword.

Coming from C, I once tried to learn C++, which I found rather confusing. D
seemed like an easier alternative, but in a sense it requires C++ knowledge
anyway. A standalone, no prior knowledge requiring D tutorial would be useful.
(More detailed, comprehensive and up-to-date than the one on dource.org.) It
doesn't seem that there is something in hand, however.
Anyway, thanks for your hints, they made things clearer for me. I'll also look
into some C++ books. You are probably right in that this is a faster way to
finally "get" it.

Thanks again,
Mathias


1 2
Next ›   Last »