线程池返回多个异常的处理方式
try { var model = await api.GetAsync(); } catch (HttpRequestException ex) when (ex.InnerException is ApiInvalidConfigException configException) { // 请求配置异常 } catch (HttpRequestException ex) when (ex.InnerException is ApiResponseStatusException statusException) { // 响应状态码异常 } catch (HttpRequestException ex) when (ex.InnerException is ApiException apiException) { // 抽象的api异常 } catch (HttpRequestException ex) when (ex.InnerException is SocketException socketException) { // socket连接层异常 } catch (HttpRequestException ex) { // 请求异常 } catch (Exception ex) { // 异常 }
可以通过when对内部异常进行捕获处理。如果when后面的多个分支都满足则XXXXX