- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码片段用于测试目的;
fun main() {
val myScope = CoroutineScope(Dispatchers.Default) + Job()
myScope.launch {
val job = async {
delay(1000)
throw RuntimeException("shiiiet")
}
try {
job.await()
} catch (ret: RuntimeException){
throw RuntimeException("yooo!")
}
}
try {
Thread.sleep(5000)
} catch(e: Exception){
}
println("wohoooo!")
}
launch
会将异常传播到父作用域,并且由于父作用域不处理它,它会在到达打印语句时使 JVM 崩溃。
最佳答案
您尝试了多个 throw
和 catch
在你的例子中的方法。async
按预期工作 - 当您 await
为此,您可以捕获异常。但是如果你launch
一个协程,默认Thread.uncaughtExceptionHandler
只是将结果打印到控制台。
即使你这样做
myScope.launch {
....
}.invokeOnCompletion { e -> println("Exception: $e") }
fun main() = runBlocking {
try {
GlobalScope.launch {
delay(10)
throw Exception("You don't catch me in main.")
}
launch {
delay(10)
throw Exception("You catch me in main.")
}
delay(100)
println("Never reached.")
} catch(e: Exception) {
println("Caught in main: ${e.cause}")
}
println("The end")
}
关于kotlin - 范围是否在幕后默默地处理异常/失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60658586/
对于要执行的JS代码,由解析器逐行解析,如果代码无效,则显示错误信息。如果一切正确,那么解析器会生成一个称为抽象语法树的数据结构。然后使用此抽象语法树为解释器生成字节码以供执行。 以上快速分析可以总结
似乎如果我在 () 中包装一个字符串、 bool 值或数字原始值,我会得到一个包装原始值的字符串、 bool 值、数字对象。这个结论正确吗? 此外,似乎 () 对于字符串和 bool 值是可选的,但对
我有几个关于 Java 中的嵌套类的问题。 关于内存分配,嵌套类是如何“隐藏”的? 您不能在嵌套类中声明静态变量(我认为确切的错误是静态属性只能在顶级类中声明)。为什么会这样?嵌套类还有哪些其他限制?
对于没有使用 Lambda Expresstions 经验的人,下面的代码让它看起来很神奇: int totalScore = File.ReadLines(@"c:/names.txt")
一个朴素的类型系统会将对象存储为指向其类型的指针(其中包含许多有用的信息,如 vtable、对象大小等),然后是其数据。如果.Net 有这样的类型系统,object在 32 位系统上占用 4 个字节,
我有以下用于字符串加密和解密的JAVA代码: public class AES { private SecretKeySpec setKey(String myKey) {
我试图了解 React 中的“组件”。 我有几个问题,所以我认为社区是提出问题的最佳场所。 1 - 当我们这样做时: var foo = React.createClass ({ ... }); Co
我想知道 ref 和 out 关键字在幕后是如何工作的?例如,如果我们在方法上使用它,它会把这个值类型变量放入某个类中以便像使用引用类型一样使用它吗? 最佳答案 in order to work wi
我对 Rails ActiveRecord、Doctrine for PHP(以及类似的 ORM)背后的一些设计很感兴趣。 ORM 如何设法实现链式访问器等功能,它们通常需要多深的工作? ORM 如何
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: C# “as” cast vs classic cast 我想知道当我做类似的事情时,.Net CLR 的底
好吧,这似乎是一个菜鸟问题,但我认识的许多 Web 开发人员都没有完全理解这个问题。 基本上,如何使用 FileUpload 控件的上传事件将文件从网页文件输入框上传到网络服务器(例如托管 .net
我很熟悉,按下返回键会导致 activity 被“销毁”,或者当开发人员调用函数 finish() 时,或者当系统需要时内存等... 并且还熟悉我们需要在 onDestroy 中执行清理过程,例如 u
我正在使用 GameViewController 和 GameScene。这个链接到 GameScene.sks。在 GameViewController 中,我将 aspect radio 设置为
关于 EF 的另一个问题: 我想知道在遍历查询结果时幕后发生了什么。 例如,查看以下代码: var activeSources = from e in entitiesContext.Sources
你好,我有一个关于 d3 的性质的问题,我认为这是关于 d3 的非常深入的细节。 据我了解, d3 中的变量声明,如 var svg = d3.select('boby').append('svg'
我是一名优秀的程序员,十分优秀!