018/Go-Programming-Examples
/src/main/java/com/qwen/examples/exception/MyException1.java
package com.qwen.examples.exception;
/**
* Created by qwen on 2018/2/28.
*/
public class MyException1 extends Exception{
public MyException1(String message){
super(message);
}
}
/src/main/java/com/qwen/examples/exception/MyException3.java
package com.qwen.examples.exception;
/**
* Created by qwen on 2018/2/28.
*/
public class MyException3 extends Exception {
public MyException3(String message){
super(message);
}
}
/src/main/java/com/qwen/examples/exception/MyException4.java
package com.qwen.examples.exception;
/**
* Created by qwen on 2018/2/28.
*/
public class MyException4 extends Exception {
public MyException4(String message){
super(message);
}
}
/src/main/java/com/qwen/examples/exception/MyException5.java
package com.qwen.examples.threads;
/**
* Created by qwen on 2018/2/28.
*/
public class MyThread extends Thread {
private String threadName;
public MyThread(String threadName) {
this.threadName = threadName;
}
public String getThreadName() {
return threadName;
}
public void setThreadName(String threadName) {
this.threadName = threadName;
}
@Override
public void run() {
for (int i = 1; i <= 10; i++) {
System.out.println("线程名:" + threadName + " 循环次数:" + i);
}
}
}
/src/main/java/com/qwen/examples/threads/MyThread.java
package com.qwen.examples.threads;
/**
* Created by qwen on 2018/2/28.
*/
public class MyThreadDemo {
public static void main(String[] args) {
MyThread thread1 = new MyThread("线程1");
MyThread thread2 = new MyThread("线程2");
thread1.start();
thread2.start();
}
}
/src/main/java/com/qwen/examples/exception/MyException2.java
package com.qwen.examples;
/**
* Created by qwen on 2018/2/28.
*/
public class MyException {
public static void main(String[] args) {
// 1. 调用一个方法
test1();
// 2. 通过try-catch捕获异常
test2();
// 3. 通过throw抛出异常
test3();
// 4. 通过throw抛出异常
test4();
// 5. 通过throw抛出异常
test5();
}
/**
* 1. 调用一个方法
*/
private static void test1() {
try {
// 调用一个方法
test2();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 2. 通过try-catch捕获异常
*/
private static void test2() {
try {
// 调用一个方法
test3();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 3. 通过throw抛出异常
*/
private static void test3() {
try {
// 调用一个方法
test4();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 4. 通过throw抛出异常
*/
private static void test4() {
try {
// 调用一个方法
test5();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 5. 通过throw抛出异常
*/
private static void test5() {
throw new MyException2("这是一个异常");
}
}
/src/main/java/com/qwen/examples/exception/MyException.java
package com.qwen.examples.threads;
import com.qwen.examples.threads.MyThread;
/**
* Created by qwen on 2018/2/28.
*/
public class MyThreadDemo {
public static void main(String[] args) {
MyThread thread1 = new MyThread("线程1");
MyThread thread2 = new MyThread("线程2");
thread1.setThreadName("线程1");
thread2.setThreadName("线程2");
thread1.start();
thread2.start();
}
}
/src/main/java/com/qwen/examples/exception/MyException2.java
package com.qwen.examples.threads;
/**
* Created by qwen on 2018/2/28.
*/
public class MyThreadDemo {
public static void main(String[] args) {
MyThread thread1 = new MyThread("线程1");
MyThread thread2 = new MyThread("线程2");
thread1.setThreadName("线程1");
thread2.setThreadName("线程2");
thread1.start();
thread2.start();
}
}
/src/main/java/com/qwen/examples/exception/MyException3.java
package com.qwen.examples.threads;
/**
* Created by qwen on 2018/2/28.
*/
public class MyThreadDemo {
public static void main(String[] args) {
MyThread thread1 = new MyThread("线程1");
MyThread thread2 = new MyThread("