1

I am trying to create an extension to wrap an existing DLL without extensive knowledge of C/++. I have used the sample extension as a base and everything seems to work fine, what I would like to do is have some error handling inside my dll.

Is there a way of sending custom errors back to dart if something inside the dll fails? Would it just be a case of sending lets say an array with the first parameter being a bool as to whether it failed or not and the second parameter being a string for the error if there is one. Or is there an actual way to throw errors from the dll itself?

Hope this made sense, Thanks,

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Tom C
  • 822
  • 7
  • 27

1 Answers1

2

You should take a look inside dart_api.h file, it contains a lot of comments about Dart native stuff.

I have found Dart_ThrowException function there, but also a comment saying that Dart_NewUnhandledExceptionError should be used instead.

Both functions need a Dart exception object handle. It seems that Dart team uses their own Dart Util library to create them:

Dart_ThrowException(DartUtils::NewDartArgumentError("error message"))
Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
  • Sorry forgot to mark this as the answer. I dug around their util library and extracted the functions I required to create a custom exception. It basically involved creating a new instance of my exception class and sending it to dart. Thank you for your response :) – Tom C Feb 18 '14 at 20:45
  • It seems like `Dart_ThrowException` will be removed in the future and the recommended way is using `Dart_NewUnhandledExceptionError` to create the Exception object and then using `Dart_PropagateError` to propagate it back to Dart. – martin Jun 27 '15 at 21:28