I recently came 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 am wondering which variable e is in the catch clause:
catch(e) { ... }
Obviously, this is a kind of exception , but (1) why do not we need to specify its type, and (2) what can I add there to indicate its specific type? For example, how could I handle several types of possible exceptions similarly to catchError(someHandler, test: (e) => e is SomeException) ?
exception-handling try-catch dart
IAmYourFaja
source share