Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there support for predefined macros in DART

Does DART support predefined macros such as:

__LINE__

or

__FUNCTION__

The reason for asking is that the transformer DART2JS makes the console log not useful as all the logs shows: js_primitives.dart:30

[update BasE]

When using the transformer dart2js, print("hello world"); will result in:

JS('void', r'console.log(#)', "hello world);

to be invoked from function: printString(String string) residing in the library dart2js._js_primitives

This results that the console.log message always contains the same line number over and over again wherever in the DART code a print(); is used. (As console.log will add automatically the filename and line-number to the console display of the wrapper function residing in dart2js._js_primitives) As the current implementation of adding file-name and line-number to the console.log message is useless, it would have been nice if there would be another method that allows to display additional information.

As example, print("hello world" __FUNCTION__ __LINE__); would result in additional debug information that can be more useful.

like image 641
Bas E Avatar asked Dec 08 '25 17:12

Bas E


1 Answers

You could use

void main() {
  print(StackTrace.current);
}

to get better information about the source of the error

DartPad example

You can also run your code in a custom zone and define a custom print method for that zone. See also https://api.dartlang.org/stable/1.24.3/dart-async/Zone/print.html

like image 115
Günter Zöchbauer Avatar answered Dec 10 '25 21:12

Günter Zöchbauer