New Issue Checklist

  • [x] I have searched for a similar issue in the project and found none

Issue Info

| Info | Value | |
| ------------------------------ | ----------------------------------------------------- | ---- |
| Platform Name | e.g. flutter / windows10/ android | |
| Platform Version | e.g. 1.22.4 / 10 / 9.0 | |
| Dio Version | e.g. 3.0.10 | |
| Visual Studio Code Version | e.g. 1.52.1 | |
| Repro rate | e.g. all the time (100%) / sometimes x% / only once | |

Issue Description and Steps

我使用leancloud的SDK,当对方服务器返回400错误的时候,vsc 就会跳到这个页面:

dio.dart 第966行
} catch (e) {
throw assureDioError(e, options);
}
并有红色提示:
Exception has occurred.
DioError (DioError [DioErrorType.RESPONSE]: Http status error [400])

于是我跟踪到此SDK的post动作,输出一些发送的数据与参数:
SDK 的文件 lc_http_client.dart , line70:

try {
print('=====1.The params to post:====={');
print(path);
print(options);
print(data);
print(queryParams);
print('=====1.The params to post:=====}');

  Response response = await _dio.post(path,
      options: options, data: data, queryParameters: queryParams);
  return response.data;
} on DioError catch (e) {
  print('=====2.Here catch DioError:====={');
  print(e);
  print('=====2.Here catch DioError:=====}');
  _handleError(e);  //此函数可以在这里点击查看 [ _handleError(e);](https://github.com/leancloud/Storage-SDK-Flutter/blob/985f9ad91e3b1d5824fd3340c68d6010a6c606e3/lib/internal/http/lc_http_client.dart)
}

我也附上我本身的业务逻辑的代码:
try {
developer.log('======Begin :=======');
await LCSMSClient.requestSMSCode(_phoneNumber);
}on DioError catch (e){
developer.log('======DioError catch=======');
} on LCException catch (e) {
developer.log('======LCException catch=======');
developer.log(e.message);
} catch (e) {
developer.log('======catch=======');
}

输出如下:
[log] ======Begin :=======
I/flutter ( 1793): =====1.The params to post:====={
I/flutter ( 1793): requestSmsCode
I/flutter ( 1793): Instance of 'Options'
I/flutter ( 1793): {"mobilePhoneNumber":"+8625786"}
I/flutter ( 1793): null
I/flutter ( 1793): =====1.The params to post:=====}
I/flutter ( 1793): =====2.Here catch DioError:====={
I/flutter ( 1793): DioError [DioErrorType.RESPONSE]: Http status error [400]
I/flutter ( 1793): =====2.Here catch DioError:=====}
[log] ======LCException catch=======
[log] 无效的手机号码。

问题:看输出,dio.post执行之后是可以catch到DioError的,但是为什么VSC编辑器每次都会跳转到
throw assureDioError(e, options);
并有红色提示呢?

即使我改为如下,不用on DioError或改为catchError,还是会跳转到throw assureDioError(e, options);并有红色提示。

try {
developer.log('======Begin :=======');
await LCSMSClient.requestSMSCode(_phoneNumber).catchError(( /DioError/ e) {
developer.log('======I am catchError=======');
});
}catch (e) {
developer.log('======catch=======');
}
输出:
V/AudioManager( 7109): querySoundEffectsEnabled...
[log] ======Begin :=======
[log] ======I am catchError=======

这里明显可以catch到,但为什么还会在throw assureDioError(e, options);里面抛出来呢?求大侠指导!
(已在github提出问题,希望尽快得到答复,谢谢:https://github.com/leancloud/Storage-SDK-Flutter/issues/98)

是不是因为这个异常更底层,而 VSCode 开了 Exception Breakings 导致的断点呢?

这样VCS并不会有任何跳转与报错,
try {
throw FormatException('Test');
}catch (e) {
developer.log('======catch you!=======');
}

正常输出:
[log] ======catch you!=======
catch正常!

我不太理解你的意思。
我理解的是在 debug 过程中,有些底层的异常中断了程序,没有走到预期的 catch 中。这并不是说 catch 不会执行到,而是说由于 vscode 的设置(会在所有异常的地方中断,调用栈是由底层到高层的),所以再往上抛几层就可以走到预期的 catch 中。
如果你不需要所有异常都中断,你可以在需要的地方打断点就可以了。

不好意思,请问“底层的异常”能否解决呢?会是flutter的错误还是dio或leancloud官方代码的错误呢?我没有任何断点。另外,能告诉我vscode 的设置在哪里修改吗?我对vscode不太熟

你试下不用处理这个异常,继续向上运行,看看能不能到捕获 DioError 的代码中