Dart catch clause

Viewed 41835

I recently stumbled across the following Dart code:

void doSomething(String url, String method) {
    HttpRequest request = new HttpRequest();

    request.open(method, url);
    request.onLoad.listen((event) {
        if(request.status < 400) {
            try {
                String json = request.responseText;
            } catch(e) {
                print("Error!");
            }
        } else {
            print("Error! (400+)");
        }
    });

    request.setRequestHeader("Accept", ApplicationJSON);
}

I'm wondering what the e variable is in the catch clause:

catch(e) {
    ...
}

Obviously its some sort of exception, but (1) why do we not need to specify its type, and (2) what could I add in there to specify its concrete type? For instance, how could I handle multiple types of possible exceptions in a similar way to catchError(someHandler, test: (e) => e is SomeException)?

1 Answers
Related