此函数会产生错误:
static Future<String> createTable() async {
try {
var map = Map<String, dynamic>();
map['action'] = 'CREATE_TABLE';
final response = await http.post(ROOTurl, body: map);
print('Create Table Response: ${response.body}');
if (200 == response.statusCode) {
return response.body;
} else {
return "error";
}
} catch (e) {
return "error"+e;
}}
完全例外:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'SocketException' is not a subtype of type 'String'
有什么办法可以解决这个问题?
答案 0 :(得分:1)
您正在尝试将非字符串类型的String
连接起来
尝试一下:
try {
//code throwing exceptions
} on SocketException catch (e) {
print('error ${e.message}');
} catch (e) {
//for other errors
print('error ${e.toString()}');
}