digitalmars.D - Unreachable statement, do or do not, there is no try
- deadalnix (27/27) Feb 09 2015 DMD accept both :
- Jacob Carlborg (4/25) Feb 09 2015 DMD will complain about the second example if warnings are enabled.
- deadalnix (3/5) Feb 09 2015 Ok I think that answer the question.
- Walter Bright (3/6) Feb 10 2015 The thing is, you can still catch an Object, so catching Exception won't...
- Matthias Bentrup (2/11) Feb 10 2015 s/Object/Error/ ?
- deadalnix (4/13) Feb 10 2015 yes, but if you don't catch, then you continue unwinding, so
- Walter Bright (3/14) Feb 10 2015 I agree the flow analysis code (which is pretty simplistic) should be lo...
- Jonathan M Davis via Digitalmars-d (11/18) Feb 10 2015 Wait, what? I thought that something had to be a Throwable to be throwab...
- Walter Bright (2/4) Feb 10 2015 Checking the code, I see it now requires Throwable. (D1 required only Ob...
- H. S. Teoh via Digitalmars-d (5/11) Feb 10 2015 I'm sure glad we moved away from that!!
- Jonathan M Davis via Digitalmars-d (4/12) Feb 10 2015 Agreed.
- Idan Arye (4/13) Feb 12 2015 Why does it matter in that example? If a non-Exception Throwable
DMD accept both : int foo() { try { throw new Exception("blah"); } catch(Exception e) { return 25; } } and int foo() { try { throw new Exception("blah"); } catch(Exception e) { return 25; } return 42; } Which is it ? What are the rule for the unreachable statment ? It seems that DMD is capable of figuring out that the try never returns, or it would complain about missing return in the first case. But that do not seems consistent with not triggering the unreachable statement in case 2. I'm working on improving control flow analysis in SDC. My handling of try will error on case 2. Is that the right thing ? Also, if it is possible to detect that a statement finishes, without triggering a unreachable statement error, is that possible to make it so for static ifs ?
Feb 09 2015
On 2015-02-09 20:00, deadalnix wrote:DMD accept both : int foo() { try { throw new Exception("blah"); } catch(Exception e) { return 25; } } and int foo() { try { throw new Exception("blah"); } catch(Exception e) { return 25; } return 42; } Which is it ? What are the rule for the unreachable statment ? It seems that DMD is capable of figuring out that the try never returns, or it would complain about missing return in the first case. But that do not seems consistent with not triggering the unreachable statement in case 2.DMD will complain about the second example if warnings are enabled. -- /Jacob Carlborg
Feb 09 2015
On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 09 2015
On 2/9/2015 11:07 PM, deadalnix wrote:On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 10 2015
On Tuesday, 10 February 2015 at 20:37:16 UTC, Walter Bright wrote:On 2/9/2015 11:07 PM, deadalnix wrote:s/Object/Error/ ?On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 10 2015
On Tuesday, 10 February 2015 at 20:37:16 UTC, Walter Bright wrote:On 2/9/2015 11:07 PM, deadalnix wrote:yes, but if you don't catch, then you continue unwinding, so whatever road you take, there is no way you reach whatever comes after the try.On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 10 2015
On 2/10/2015 12:48 PM, deadalnix wrote:On Tuesday, 10 February 2015 at 20:37:16 UTC, Walter Bright wrote:I agree the flow analysis code (which is pretty simplistic) should be looked at again. You should file a bugzilla.On 2/9/2015 11:07 PM, deadalnix wrote:yes, but if you don't catch, then you continue unwinding, so whatever road you take, there is no way you reach whatever comes after the try.On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 10 2015
On Tuesday, February 10, 2015 12:36:50 Walter Bright via Digitalmars-d wrote:On 2/9/2015 11:07 PM, deadalnix wrote:Wait, what? I thought that something had to be a Throwable to be throwable or catchable. Allowing any Object to be thrown/caught stinks of the C++ nonsense of allowing _anything_ to be thrown/caught. It's slightly better, because it's restricted to Objects and stuff like arrays and ints wouldn't count, but it would still be pretty horrible to be throwing Objects that aren't intended to be used as exception types. And anything that isn't derived from Exception being thrown could result in cleanup code not being run. If something other than a Throwable can currently be thrown, I would hope that we'd fix it so that that's no longer the case. - Jonathan M DavisOn Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 10 2015
On 2/10/2015 7:49 PM, Jonathan M Davis via Digitalmars-d wrote:Wait, what? I thought that something had to be a Throwable to be throwable or catchable.Checking the code, I see it now requires Throwable. (D1 required only Object.)
Feb 10 2015
On Tue, Feb 10, 2015 at 09:00:33PM -0800, Walter Bright via Digitalmars-d wrote:On 2/10/2015 7:49 PM, Jonathan M Davis via Digitalmars-d wrote:I'm sure glad we moved away from that!! T -- Once the bikeshed is up for painting, the rainbow won't suffice. -- Andrei AlexandrescuWait, what? I thought that something had to be a Throwable to be throwable or catchable.Checking the code, I see it now requires Throwable. (D1 required only Object.)
Feb 10 2015
On Tuesday, February 10, 2015 21:25:51 H. S. Teoh via Digitalmars-d wrote:On Tue, Feb 10, 2015 at 09:00:33PM -0800, Walter Bright via Digitalmars-d wrote:Thanks!On 2/10/2015 7:49 PM, Jonathan M Davis via Digitalmars-d wrote:Wait, what? I thought that something had to be a Throwable to be throwable or catchable.Checking the code, I see it now requires Throwable. (D1 required only Object.)I'm sure glad we moved away from that!!Agreed. - Jonathan M Davis
Feb 10 2015
On Tuesday, 10 February 2015 at 20:37:16 UTC, Walter Bright wrote:On 2/9/2015 11:07 PM, deadalnix wrote:Why does it matter in that example? If a non-Exception Throwable is thrown the return after the try..catch will still not be reached.On Tuesday, 10 February 2015 at 07:01:18 UTC, Jacob Carlborg wrote:The thing is, you can still catch an Object, so catching Exception won't quite catch them all.DMD will complain about the second example if warnings are enabled.Ok I think that answer the question.
Feb 12 2015