throws Exception in method

2014-05-08 Thread amehat via Digitalmars-d-learn
Hello everyone, in java, you can have exceptions on methods. Thus we can write: public static void control (String string) throws MyException {} Is that possible in D and if so how does it work? If I write this D: public void testMe () throws MyException {} The compiler refuses to compile.

Re: throws Exception in method

2014-05-08 Thread John Colvin via Digitalmars-d-learn
On Thursday, 8 May 2014 at 09:15:16 UTC, amehat wrote: Hello everyone, in java, you can have exceptions on methods. Thus we can write: public static void control (String string) throws MyException {} Is that possible in D and if so how does it work? If I write this D: public void testMe ()

Re: throws Exception in method

2014-05-08 Thread bearophile via Digitalmars-d-learn
amehat: What is the proper behavior for this D? D doesn't have that Java syntax, because it was widely regarded as a Java design mistake. So in D omit the throws part. If your function tree doesn't throw exceptions (but it can throw errors) add a nothrow. Bye, bearophile

Re: throws Exception in method

2014-05-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Thu, 08 May 2014 09:15:13 + amehat via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hello everyone, in java, you can have exceptions on methods. Thus we can write: public static void control (String string) throws MyException {} Is that possible in D and if so how

Re: throws Exception in method

2014-05-08 Thread amehat via Digitalmars-d-learn
(and functions) can raise exceptions, unless it has nothrow. And if I still includes exceptions that are thrown are at the time of compilation. So I can not write: public void testMe () throws MyException {} However, if I write this and my method throws an exception, it will take place

Re: throws Exception in method

2014-05-08 Thread John Colvin via Digitalmars-d-learn
this and my method throws an exception, it will take place at compile time: public void testMe () {} And if do not want an exception thrown, I should write: public void testMe () : nothrow {} or perhaps : public void testMe () pure nothrow @safe {} Is that correct? PS: Thanks for the article

Re: throws Exception in method

2014-05-08 Thread amehat via Digitalmars-d-learn
testMe () throws MyException {} However, if I write this and my method throws an exception, it will take place at compile time: public void testMe () {} And if do not want an exception thrown, I should write: public void testMe () : nothrow {} or perhaps : public void testMe () pure nothrow

Re: throws Exception in method

2014-05-08 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 8 May 2014 at 13:06:05 UTC, amehat wrote: Okay. Thank you for these explanations, I understand a little better the exceptions D. Keep in mind that D also has the concept of Error. Both Exception and Error derive from Throwable. nothrow only means the function will not throw an

Re: throws Exception in method

2014-05-08 Thread amehat via Digitalmars-d-learn
On Thursday, 8 May 2014 at 14:02:06 UTC, monarch_dodra wrote: On Thursday, 8 May 2014 at 13:06:05 UTC, amehat wrote: Okay. Thank you for these explanations, I understand a little better the exceptions D. Keep in mind that D also has the concept of Error. Both Exception and Error derive from

Re: throws Exception in method

2014-05-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 08, 2014 at 03:19:04PM +, amehat via Digitalmars-d-learn wrote: On Thursday, 8 May 2014 at 14:02:06 UTC, monarch_dodra wrote: [...] Keep in mind that D also has the concept of Error. Both Exception and Error derive from Throwable. nothrow only means the function will not