Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try...finally adds strange lines to stacktraces #12584

Closed
andersjohnsen opened this issue Aug 21, 2013 · 8 comments
Closed

try...finally adds strange lines to stacktraces #12584

andersjohnsen opened this issue Aug 21, 2013 · 8 comments
Labels

Comments

@andersjohnsen
Copy link

Consider the following:

void main() {
  try {
    throw "error";
  } finally {
  }
}

Here the VM adds two extra lines to the stacktrace:

Unhandled exception:
error

­0 main (file:///usr/local/google/home/ajohnsen/src/dart/dart/dev/simple_io.dart:3:5)

­1 main (file:///usr/local/google/home/ajohnsen/src/dart/dart/dev/simple_io.dart:4:5)

­2 main (file:///usr/local/google/home/ajohnsen/src/dart/dart/dev/simple_io.dart:4:5)

Note how line 5 is the line containing the '} finally {'. I would not expect the stacktrace to contain those lines at all.

(same goes for try..catch, but that will only add 1 line).

@andersjohnsen
Copy link
Author

And by line 5 i of course mean line 4 :)

@kmillikin
Copy link

Thanks for the report.

This is an artifact of the way we implement try-finally without a catch (or without a generic catch). We compile the program as if it were written:

void main() {
  try {
    throw "error";
  } catch on Object (e) {
    rethrow;
  } finally {
    // Any finally code.
  }
}

However, we further compile finally by translating it away (!), so we compile this new program as if it were written:

void main() {
  try {
    throw "error";
  } catch on Object (e) {
    try {
      rethrow;
    } catch on Object (e) {
      // Any finally code.
      rethrow;
    }
  }
  // Any finally code.
}

That is: we have introduced two new hidden rethrows and two new hidden catch clauses. We use the same source code position for both of them, which is the position of the original "finally".

I think the easiest fix is to mark the handlers for the two introduced catches as 'hidden' and not include them in the stack trace in the same way that we don't include hidden functions in the stack trace.

I'll try to get to that next week unless someone else on the team wants to steal this.


cc @iposva-google.
Set owner to @kmillikin.
Added Accepted label.

@iposva-google
Copy link
Contributor

We have discussed a completely revamped exception handling mechanism, which will likely make fixing this unnecessary. I am keeping this open though so that we can verify that it will be fixed as a "side-effect".


Removed the owner.
Added Triaged label.

@iposva-google
Copy link
Contributor

cc @sgmitrovic.

@rakudrama
Copy link
Member

This program also has a messed-up stack.
This is at r27580.
Is it the same problem?


import 'dart:typed_data';

class C {
  operator<(o) => false;
  operator<=(o) => true;
  operator==(o) => true;
  operator>=(o) => false;
  operator>(o) => true;
  //operator*(o) => this;
}

main() {
  var a = new Float32List(10);
  a[new C()];
}


$ sdk/bin/dart ~/play1/bug6V9.dart
Unhandled exception:
Class 'C' has no instance method '*'.

NoSuchMethodError : method not found: '*'
Receiver: Instance of 'C'
Arguments: [4]
#­0 Object.noSuchMethod (dart:core-patch/object_patch.dart:20:25)
#­1 Float32List._getIndexedFloat32 (dart:typed_data-patch/typed_data.dart:826:30)
#­2 Float32List.
#­3 main (file:///home/sra/play1/bug6V9.dart:15:4)
#­4 Float32List._getIndexedFloat32 (dart:typed_data-patch/typed_data.dart:826:30)
#­5 Float32List.
#­6 main (file:///home/sra/play1/bug6V9.dart:15:4)
$


@iposva-google
Copy link
Contributor

The issue in comment #­5 is different as there are no finally blocks involved. That report looks more like a simpler reproduction of issue #9.

@fsc8000
Copy link
Contributor

fsc8000 commented Oct 23, 2013

Both have n frames duplicates, in #­5 n=3, for #­1 n=1. This really should be fixed. Any progress?

@fsc8000
Copy link
Contributor

fsc8000 commented Jan 12, 2015

This seems to be fixed as the example is not reproducible anymore.

Unhandled exception:
error
#­0 main (file:///media/SSD/dart2/dart/try1.dart:3:5)
#­1 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:260)
#­2 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:142)


Added Fixed label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants