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

Exception.stack is missing the throwing line in Haxe 4.3.x #11247

Closed
giuppe opened this issue Jun 7, 2023 · 1 comment · Fixed by #11249
Closed

Exception.stack is missing the throwing line in Haxe 4.3.x #11247

giuppe opened this issue Jun 7, 2023 · 1 comment · Fixed by #11249
Assignees

Comments

@giuppe
Copy link

giuppe commented Jun 7, 2023

Starting with 4.3.0, getting the stack of an exception via Exception.stack or Exception.details() seems to not contain the throwing line infos anymore; however, ClassStack.exceptionStack() is still the same.

https://try.haxe.org/#6bF30094

import haxe.Exception;
import haxe.CallStack;

class Test {
	static function main() {
		try {
			f1();
		} catch (e) {
			trace("\n stack: " + e.stack);
			trace("\n CallStack.exceptionStack: " + CallStack.toString(CallStack.exceptionStack()));
			trace("\n details: " + e.details());
		}
	}

	static function f1() {
		f2();
	}

	static function f2() {
		var a:Array<Int> = null;
		if(a == null)
			throw "a is null";   // this is line 22
	}
}

The actual exception is thrown on line 22.

This is the output in 4.3.0 and 4.3.1 (tested in neko, hashlink, hxcpp):

Test.hx:9: 
 stack: 
Called from Test.hx line 16
Called from Test.hx line 7
Test.hx:10: 
 CallStack.exceptionStack: 
Called from Test.hx line 22
Called from Test.hx line 16
Called from Test.hx line 7
Test.hx:11: 
 details: Exception: a is null
Called from Test.hx line 16
Called from Test.hx line 7

Although in 4.2.5:

Test.hx:9: 
 stack: 
Called from Test.hx line 21
Called from Test.hx line 16
Called from Test.hx line 7
Called from ? line 1
Test.hx:10: 
 CallStack.exceptionStack: 
Called from Test.hx line 21
Called from Test.hx line 16
Called from Test.hx line 7
Test.hx:11: 
 details: Exception: a is null
Called from Test.hx line 21
Called from Test.hx line 16
Called from Test.hx line 7
Called from ? line 1

I made other experiments:

  • If the exception is thrown via something like:
var a:Array<Int> = null;
trace(a.length);  // Null access .length

Then only CallStack.exceptionStack contains the throwing line, even in Haxe 4.2.x.

  • If the exception is thrown by explicitly creating an Exception object, the throwing line is present everywhere:
var a:Array<Int> = null;
if(a == null)
    throw new Exception("a is null");

Is this a bug, or are we supposed to get the throwing line in some other way?

@kLabz kLabz self-assigned this Jun 8, 2023
@kLabz
Copy link
Contributor

kLabz commented Jun 8, 2023

Bisected to fb52486 / #10519

kLabz added a commit that referenced this issue Jul 5, 2023
…11249)

* [tests] add test for #11247

* Fix for #11247

* [hl] restore callstack fix

* [tests] cpp doesn't like native exceptions in those tests either

* [tests] only run new test for eval/hl/neko

* Fix #11265

* [tests] don't compile test on target that won't run it
kLabz added a commit that referenced this issue Aug 31, 2023
…11249)

* [tests] add test for #11247

* Fix for #11247

* [hl] restore callstack fix

* [tests] cpp doesn't like native exceptions in those tests either

* [tests] only run new test for eval/hl/neko

* Fix #11265

* [tests] don't compile test on target that won't run it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants