exceptions - mkol/il2js GitHub Wiki

Partial support for exceptions. Following types of exceptions can be handled:

  • JavaScript exceptions - thrown by native JavaScript methods,
    • this include AJAX calls exceptions (timeouts, non 200 return code, invalid JSON parsing)
  • .NET client-side exceptions - thrown using throw keyword,
  • .NET server-side exceptions - thrown by methods invoked at server.

Handling server-side exceptions

[RunAt(RunAt.Server, HideExceptionMessage = true)]
public static void Throw1() {
	throw new Exception("Error message");
}

[RunAt(RunAt.Server)]
public static void Throw2() {
	throw new Exception("Error message");
}

protected void Page_Load() {
	try {
		Throw1();
	} catch(Exception e){
		Alert(e.Message) // shows empty string
	}
	try {
		Throw2();
	} catch(Exception e){
		Alert(e.Message) // "Error message"
	}
}

No other fields than message are copied to the client. When HideExceptionMessage is present, even message isn't copied.

Also type of Exception is hidden. (All exceptions are repackaged to standard Exception.)

Limitations

Exception handling clauses ingore exception types

try{
	// ...
} catch(IOException e) {
	// code from this block is executed for all types of exceptions
}

Only first catch is compiled

try {
	// ...
} catch(ExceptionType1 e) {
	// code from this block is compiled
} catch(ExceptionType2 e) {
	// code from this block is ignored!
} catch {
	// code from this block is compiled
} finally {
	// code from this block is compiled
}
⚠️ **GitHub.com Fallback** ⚠️