Java 实例 - 多线程异常处理

Java 教程 · 2019-02-11 10:28:10

以下实例演示了多线程异常处理方法:

Main.java 文件

class MyThread extends Thread{ public void run(){ System.out.println("Throwing in " +"MyThread"); throw new RuntimeException(); } } class Main { public static void main(String[] args){ MyThread t = new MyThread(); t.start(); try{ Thread.sleep(1000); } catch (Exception x){ System.out.println("Caught it" + x); } System.out.println("Exiting main"); } }

以上代码运行输出结果为:

Throwing in MyThread
Exception in thread "Thread-0" java.lang.RuntimeException
        at testapp.MyThread.run(Main.java:19)
Exiting main

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Network Algorithmics,

Network Algorithmics,

George Varghese / Morgan Kaufmann / 2004-12-29 / USD 75.95

In designing a network device, you make dozens of decisions that affect the speed with which it will perform - sometimes for better, but sometimes for worse. "Network Algorithmics" provides a complete......一起来看看 《Network Algorithmics,》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换