Skip to content

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

@ubx-alex

Description

@ubx-alex

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);
        }

        
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions