不对。
异常分两类,runtime异常和非runtime异常。
class SelfGenerateException extends Exception {
    SelfGenerateException(String msg) {
        super(msg);   //调用Exception的构造方法
    }
    static void throwOne() throws SelfGenerateException {
        int a = 1;
        if (a == 1) {
            //如果a为1就认为在特定应用下存在异常,改变执行路径,抛出异常
            throw new SelfGenerateException("a为1");
        }
    }
    public static void main(String args[]) {
        try {
            throwOne();
        } catch (SelfGenerateException e) {
            e.printStackTrace();
        }
    }
}
结果:
SelfGenerateException: a为1
    at SelfGenerateException.throwOne(test.java:10)
    at SelfGenerateException.main(test.java:16)JDK解释如下:

当应用程序试图在需要对象的地方使用 null 时,抛出该异常。这种情况包括:
调用 null 对象的实例方法。
访问或修改 null 对象的字段。
将 null 作为一个数组,获得其长度。
将 null 作为一个数组,访问或修改其时间片。
将 null 作为 Throwable 值抛出。
应用程序应该抛出该类的实例来指示其他对 null 对象的非法使用。
public class test
{
    public static void aMethod() throws Exception{
        try{
            throw new Exception();
        }
//------------------黑体------------------------------------------------
        catch(Exception e){
            System.out.println("exception000");
        }
//----------------------------------------------------------------------
//--------------------斜体-----------------------------------------------
        finally{
            System.out.println("exception111");
        }
//---------------------------------------------------------------------------
    }
    public static void main(String[] args){
        try{
            aMethod();
        }
        catch(Exception e){
            System.out.println("exception");
        }
        System.out.println("finished");
    }
}
输出:
exception000
exception111
finished
去黑体输出:
exception111
exception
finished
如果再将斜体代码去掉:
Error:(4, 9) java: ‘try‘ 不带有 ‘catch‘, ‘finally‘ 或资源声明
就是说try不能单独存在而不带有catch或者finally声明
再去掉aMthod里的try后
输出:
exception
finished
public class test{
    public static String output ="";
    public static void foo(int i){
        try{
            if(i==1) {throw new Exception();}
            output += "1";
        }
        catch(Exception e){
            output += "2";
            return;
        }
        finally{output += "3";}
        output += "4";
    }
    public static void main(String args[]){
        foo(0);
        foo(1);
        System.out.println(test.output);
    }
}
结果:13423
解释:134是foo(0)输出的,23是foo(1)输出的。foo(1)catch里return后,也会执行finally,但是finally之后的东西就不在执行了。foo(0)不会执行return语句,所以可以执行finally后面的语句
public class test {
    public static void main(String[] args) {
        try {
            String s = null;
            System.out.println(s.charAt(0));//空指针异常
            //System.out.println(1/0);//除零异常
        } catch (NullPointerException e) {
            System.out.println("空指针异常");
        } catch (ArithmeticException e) {
            System.out.println("计算异常");
        } catch (Exception e) {
            System.out.println("其他异常");
            e.printStackTrace();
        }
    }
}
import java.util.Arrays;
import java.util.Scanner;
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[10];
        int index = 0;
        while (true) {
            try {
                arr[index] = sc.nextInt();
                if(index!=9)
                    index++;
                else{
                        break;
                }
            } catch (Exception e) {
                sc.next();
                System.out.println("输入类型有误,请重新输入");
            }
        }
        Arrays.sort(arr);
        System.out.println("max=" + arr[index]);
        System.out.println("min=" + arr[0]);
    }
}public void method()throws TimedOutException
          {
              success= connect();
              if(success == -1)
              {
                  throw new TimedOutException();
              }
          }
原文:https://www.cnblogs.com/He-Fan/p/11673083.html