当使用kotlin找不到文件时,如何从URL.readText()中获取错误

当我的手机上没有互联网,或者当这个URL不存在时,这个方法没有做任何事情,既不会崩溃也不会停止搜索。 我试过这个:

doAsync{ val json:String json = try { URL("http://10.0.2.2:8888/bac/orient.php?ort=1").readText() }catch (e: IOException){ e.printStackTrace() "" } uiThread{toast(json)} }