Exception handling in UnityJS

I must be doing something dumb here. With the below snippet, I get the following compiler error.

50    try {
51        sock.Connect(remoteEndPoint);
52    } catch(e) {
53    }

Assets/Plugins/NetworkClient.js(52,7): BCE0055: Internal compiler error: Object reference not set to an instance of an object. (Filename: Assets/Plugins/NetworkClient.js Line: 52)

I’m almost certain I’ve got the Syntax correct. What else can possibly be wrong with this snippet? The only thing I can imagine is that perhaps the try/except structure does not work inside coroutines?

After further investigation, it seems that try/except does not work inside coroutines.

Is this a bug or a feature?

I’d say it’s “by design”, see for instance:

http://en.csharp-online.net/ECMA-334:_15.14_The_yield_statement

or, for an in-depth discussions how those iterators work (which coroutines are based on):

This is all about C#, but I guess that coroutines in Unity JavaScript are also based on IEnumerators, even though it’s not explicit from the language.

Actually, sometimes it is explicit. If you recurse from one coroutine to another and back, the compiler gets confused and you must explicitly declare at least one of them as an IEnumerator.