Skip to content

Commit b0bfb84

Browse files
committed
Add getSourceLocation message to PException
1 parent 51e7586 commit b0bfb84

File tree

1 file changed

+15
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception

1 file changed

+15
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.oracle.truffle.api.library.ExportLibrary;
6767
import com.oracle.truffle.api.library.ExportMessage;
6868
import com.oracle.truffle.api.nodes.Node;
69+
import com.oracle.truffle.api.source.SourceSection;
6970

7071
/**
7172
* Serves both as a throwable carrier of the python exception object and as a represenation of the
@@ -351,5 +352,19 @@ RuntimeException throwException() {
351352
throw getExceptionForReraise();
352353
}
353354

355+
@ExportMessage
356+
@SuppressWarnings("static-method")
357+
boolean hasSourceLocation() {
358+
return getLocation() != null;
359+
}
360+
361+
@ExportMessage(name = "getSourceLocation")
362+
SourceSection getExceptionSourceLocation() throws UnsupportedMessageException {
363+
if (hasSourceLocation()) {
364+
return getLocation().getEncapsulatingSourceSection();
365+
}
366+
throw UnsupportedMessageException.create();
367+
}
368+
354369
// Note: remaining interop messages are forwarded to the contained PBaseException
355370
}

0 commit comments

Comments
 (0)