第十三天
1,异常和错误
2,异常分类:2
3,常见异常:1/0 a[1] "123a" null
4,体系架构:Throwable : Error Exception
5,异常处理:try{}catch(){}finally{}
6,没有谁,多个catch
7,final finally finalize
8,抛出异常throw throws
throws:抛出方法异常
throw:方法内部抛出异常
9,自定义异常
10,练习题
1,基本概念:ADT 表 链表 栈 队列
2,数组:优点:查找快 缺点:删除,插入效率低,存储连续空间
链表:优点:删除,插入效率高 存储零散空间 缺点:查找慢
3,链表:单向链表 双端链表 双向链表(前驱,后继)
4,优先级队列:
5,后缀表达式
A |
public class A { private int[] a; private int size; public int get(){ return a[0]; } public void add(int aa){ a[size++] = aa; } }
|
Node |
public class Node { public Node pre; public Object obj; public Node next; }
|
CjbnwfException extends RuntimeException |
public class CjbnwfException extends RuntimeException{ public CjbnwfException(){} public CjbnwfException(String message){super(message);}
}
|
|
Test |
import java.util.Scanner; public class Test { private static void abc() throws Exception{ //try{ System.out.println(1/0); //}catch (Exception e){ // e.printStackTrace(); //} } private static void bcd(){ int[] a = {1,2,3}; //try{ System.out.println(a[3]); //}catch (Exception e){ // e.printStackTrace(); //} } private static void cde(){ String s = "123a"; //try{ System.out.println(Integer.parseInt(s)); //}catch (Exception e){ // e.printStackTrace(); //} } private static void def() throws CjbnwfException{ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); if (a<0){ throw new CjbnwfException("成绩不能是负数"); } } public static void main(String[] args){ /*try { abc(); } catch (Exception e) { e.printStackTrace(); }
try{ bcd(); }catch (Exception e){ e.printStackTrace(); } try{ cde(); }catch (Exception e){ e.printStackTrace(); } try { def(); } catch (CjbnwfException e) { e.printStackTrace(); }*/ /*int a=9; int b = 0; if(b==0){ throw new ArithmeticException(); }*/ /*Scanner sc = new Scanner(System.in); int[] a = new int[5]; int count = 0; for (int i=0;i<5;i++){ try { a[i] = sc.nextInt(); count++; }catch (Exception e){ System.out.println("qing shuru zhengshu"); sc.next(); } } if (count<5){ try{ throw new Exception(); }catch (Exception e){ System.out.println("qing zhishaoshuruwugeshu"); } } */ } } |