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

Cannot catch a javascript ReferenceError in .net code v6.5.1 #516

Open
ubx-alex opened this issue Dec 7, 2016 · 1 comment
Open

Cannot catch a javascript ReferenceError in .net code v6.5.1 #516

ubx-alex opened this issue Dec 7, 2016 · 1 comment

Comments

@ubx-alex
Copy link

ubx-alex commented Dec 7, 2016

Hello,

I do not know if this is an error or is there is a way to catch this error, I have introduced an error in this example line 66 myerror is a referenceError , however I cannot catch this javascript error in my .net code and this error causes that my app closes automatically. I'm running a code like this in a big project and this is a big problem for me.

using System;
using System.Threading.Tasks;
using EdgeJs;
using System.IO;
using System.Threading;




class Program
{
    public static async void Start()
    {
        // Define an event handler to be called for every message from the client

        var onMessage = (Func<object, Task<object>>)(async (message) =>
        {
            return "Event number# " + ((string)message);
        });

        var onMessage2 = (Func<object, Task<object>>)(async (message) =>
        {
            return "Event 2 number# " + ((string)message);
        });

        var sendCommand =  (Func<object, Task<object>>)(async (message) =>
        {
            return "Command has sent" + ((string)message);
        });


        var createScriptListener = Edge.Func(@"
            const EventEmitter = require('events');
            class MyEmitter extends EventEmitter {}
            
            var i = 0;
                        


            return function (options, cb) {
                console.log('new event emitter');
                var event = new MyEmitter();
                event.on('event', function (message) {
                    options.onMessage(message, function (error, result) {
                        if (error) throw error;
                        console.log(result);
                     });
                });

                event.on('event2', function (message) {
                    options.onMessage2(message, function (error, result) {
                        if (error) throw error;
                        console.log(result);
                     });
                });
                
                event.on('sendCommand', function (message, done) {
                    options.sendCommand(message , function (error, result) {
                        if (error) throw error;
                        console.log(result);
		myerror
                        done(null, result)

                     });
                });
                
                event.on('close', function(){
                    console.log('events eventemitter bye');
                    process.exit(0);
                });

                event.emit('sendCommand', 'data from script', function(err, data){
									console.log('printing from script: ' + data);
								});
								
                cb();
            };
        ");


        try
        {
            await createScriptListener(new
            {
                onMessage = onMessage,
                onMessage2 = onMessage2,
                sendCommand = sendCommand
            });
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        
    }

    static void Main(string[] args)
    {
        try
        {
            Task.Run((Action)Start);
            new ManualResetEvent(false).WaitOne();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

        
    }
}
@ubx-alex
Copy link
Author

ubx-alex commented Dec 7, 2016

However if a change the error in this way (outside of options.sendCommand)

event.on('sendCommand', function (message, done) {
  myerror
   options.sendCommand(message , function (error, result) {
      if (error) throw error;
      console.log(result);
       done(null, result)

      })
 });

I can catch the error.

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

No branches or pull requests

1 participant