亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? module9.lst

?? Mcgraw-Hill - Java 2 - A Beginner S Guide, 2Nd Ed - 2003 -prog.
?? LST
字號(hào):
listing 1
// Demonstrate exception handling. 
class ExcDemo1 { 
  public static void main(String args[]) { 
    int nums[] = new int[4]; 
 
    try { 
      System.out.println("Before exception is generated."); 
 
      // Generate an index out-of-bounds exception. 
      nums[7] = 10; 
      System.out.println("this won't be displayed"); 
    } 
    catch (ArrayIndexOutOfBoundsException exc) { 
      // catch the exception 
      System.out.println("Index out-of-bounds!"); 
    } 
    System.out.println("After catch statement."); 
  } 
}

listing 2
/* An exception can be generated by one 
   method and caught by another. */ 
 
class ExcTest { 
  // Generate an exception. 
  static void genException() { 
    int nums[] = new int[4];  
 
    System.out.println("Before exception is generated."); 
  
    // generate an index out-of-bounds exception  
    nums[7] = 10;  
    System.out.println("this won't be displayed");  
  } 
}     
 
class ExcDemo2 {  
  public static void main(String args[]) {  
  
    try {  
      ExcTest.genException(); 
    }  
    catch (ArrayIndexOutOfBoundsException exc) {  
      // catch the exception  
      System.out.println("Index out-of-bounds!");  
    }  
    System.out.println("After catch statement.");  
  }  
}

listing 3
// Let JVM handle the error. 
class NotHandled { 
  public static void main(String args[]) { 
    int nums[] = new int[4]; 
 
    System.out.println("Before exception is generated."); 
 
    // generate an index out-of-bounds exception 
    nums[7] = 10; 
  } 
}

listing 4
// This won't work! 
class ExcTypeMismatch {  
  public static void main(String args[]) {  
    int nums[] = new int[4];  
  
    try {  
      System.out.println("Before exception is generated."); 
  
      // generate an index out-of-bounds exception  
      nums[7] = 10;  
      System.out.println("this won't be displayed");  
    }  
 
    /* Can't catch an array boundary error with an  
       ArithmeticException. */ 
    catch (ArithmeticException exc) {  
      // catch the exception  
      System.out.println("Index out-of-bounds!");  
    }  
    System.out.println("After catch statement.");  
  }  
}

listing 5
// Handle error gracefully and continue. 
class ExcDemo3 { 
  public static void main(String args[]) { 
    int numer[] = { 4, 8, 16, 32, 64, 128 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
 
    for(int i=0; i<numer.length; i++) { 
      try { 
        System.out.println(numer[i] + " / " + 
                           denom[i] + " is " + 
                           numer[i]/denom[i]); 
      } 
      catch (ArithmeticException exc) { 
        // catch the exception 
        System.out.println("Can't divide by Zero!"); 
      } 
    } 
  } 
}

listing 6
// Use multiple catch statements. 
class ExcDemo4 { 
  public static void main(String args[]) { 
    // Here, numer is longer than denom. 
    int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
 
    for(int i=0; i<numer.length; i++) { 
      try { 
        System.out.println(numer[i] + " / " + 
                           denom[i] + " is " + 
                           numer[i]/denom[i]); 
      } 
      catch (ArithmeticException exc) { 
        // catch the exception 
        System.out.println("Can't divide by Zero!"); 
      } 
      catch (ArrayIndexOutOfBoundsException exc) { 
        // catch the exception 
        System.out.println("No matching element found."); 
      } 
    } 
  } 
}

listing 7
// Subclasses must precede superclasses in catch statements. 
class ExcDemo5 { 
  public static void main(String args[]) { 
    // Here, numer is longer than denom. 
    int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
 
    for(int i=0; i<numer.length; i++) { 
      try { 
        System.out.println(numer[i] + " / " + 
                           denom[i] + " is " + 
                           numer[i]/denom[i]); 
      } 
      catch (ArrayIndexOutOfBoundsException exc) { 
        // catch the exception 
        System.out.println("No matching element found."); 
      } 
      catch (Throwable exc) { 
        System.out.println("Some exception occurred."); 
      } 
    } 
  } 
}

listing 8
// Use a nested try block. 
class NestTrys { 
  public static void main(String args[]) { 
    // Here, numer is longer than denom. 
    int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
 
    try { // outer try 
      for(int i=0; i<numer.length; i++) { 
        try { // nested try 
          System.out.println(numer[i] + " / " + 
                             denom[i] + " is " + 
                             numer[i]/denom[i]); 
        } 
        catch (ArithmeticException exc) { 
          // catch the exception 
          System.out.println("Can't divide by Zero!"); 
        } 
      } 
    }  
    catch (ArrayIndexOutOfBoundsException exc) { 
      // catch the exception 
      System.out.println("No matching element found."); 
      System.out.println("Fatal error -- program terminated."); 
    } 
  } 
}

listing 9
// Manually throw an exception. 
class ThrowDemo { 
  public static void main(String args[]) { 
    try { 
      System.out.println("Before throw."); 
      throw new ArithmeticException(); 
    } 
    catch (ArithmeticException exc) { 
      // catch the exception 
      System.out.println("Exception caught."); 
    } 
    System.out.println("After try/catch block."); 
  } 
}

listing 10
// Rethrow an exception. 
class Rethrow { 
  public static void genException() { 
    // here, numer is longer than denom 
    int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
 
    for(int i=0; i<numer.length; i++) { 
      try { 
        System.out.println(numer[i] + " / " + 
                           denom[i] + " is " + 
                           numer[i]/denom[i]); 
      } 
      catch (ArithmeticException exc) { 
        // catch the exception 
        System.out.println("Can't divide by Zero!"); 
      } 
      catch (ArrayIndexOutOfBoundsException exc) { 
        // catch the exception 
        System.out.println("No matching element found."); 
        throw exc; // rethrow the exception 
      } 
    } 
  }   
} 
 
class RethrowDemo { 
  public static void main(String args[]) { 
    try { 
      Rethrow.genException(); 
    } 
    catch(ArrayIndexOutOfBoundsException exc) { 
      // recatch exception 
     System.out.println("Fatal error -- " + 
                        "program terminated."); 
    } 
  } 
}

listing 11
// Using the Throwable methods.  
 
class ExcTest { 
  static void genException() { 
    int nums[] = new int[4];  
 
    System.out.println("Before exception is generated."); 
 
    // generate an index out-of-bounds exception  
    nums[7] = 10;  
    System.out.println("this won't be displayed");  
  } 
}     
 
class UseThrowableMethods {  
  public static void main(String args[]) {  
  
    try {  
      ExcTest.genException(); 
    }  
    catch (ArrayIndexOutOfBoundsException exc) {  
      // catch the exception  
      System.out.println("Standard message is: "); 
      System.out.println(exc); 
      System.out.println("\nStack trace: "); 
      exc.printStackTrace(); //"Index out-of-bounds!");  
    }  
    System.out.println("After catch statement.");  
  }  
}

listing 12
// Use finally. 
class UseFinally { 
  public static void genException(int what) { 
    int t; 
    int nums[] = new int[2]; 
 
    System.out.println("Receiving " + what); 
    try { 
      switch(what) { 
        case 0:  
          t = 10 / what; // generate div-by-zero error 
          break; 
        case 1: 
          nums[4] = 4; // generate array index error. 
          break; 
        case 2: 
          return; // return from try block 
      } 
    } 
    catch (ArithmeticException exc) { 
      // catch the exception 
      System.out.println("Can't divide by Zero!"); 
      return; // return from catch 
    } 
    catch (ArrayIndexOutOfBoundsException exc) { 
      // catch the exception 
      System.out.println("No matching element found."); 
    } 
    finally { 
      System.out.println("Leaving try."); 
    } 
  }   
} 
 
class FinallyDemo { 
  public static void main(String args[]) { 
     
    for(int i=0; i < 3; i++) { 
      UseFinally.genException(i); 
      System.out.println(); 
    } 
  } 
}

listing 13
// Use throws. 
class ThrowsDemo {   
  public static char prompt(String str) 
    throws java.io.IOException { 
 
    System.out.print(str + ": "); 
    return (char) System.in.read();  
  }   
 
  public static void main(String args[]) { 
    char ch; 
 
    try { 
      ch = prompt("Enter a letter"); 
    } 
    catch(java.io.IOException exc) { 
      System.out.println("I/O exception occurred."); 
      ch = 'X'; 
    } 
 
    System.out.println("You pressed " + ch); 
  } 
}

listing 14
// Use a custom exception. 
 
// Create an exception. 
class NonIntResultException extends Exception { 
  int n; 
  int d; 
 
  NonIntResultException(int i, int j) { 
    n = i; 
    d = j; 
  } 
 
  public String toString() { 
    return "Result of " + n + " / " + d + 
           " is non-integer."; 
  } 
} 
 
class CustomExceptDemo { 
  public static void main(String args[]) { 
 
    // Here, numer contains some odd values. 
    int numer[] = { 4, 8, 15, 32, 64, 127, 256, 512 }; 
    int denom[] = { 2, 0, 4, 4, 0, 8 }; 
    for(int i=0; i<numer.length; i++) { 
      try { 
        if((numer[i]%2) != 0) 
          throw new  
            NonIntResultException(numer[i], denom[i]); 
 
        System.out.println(numer[i] + " / " + 
                           denom[i] + " is " + 
                           numer[i]/denom[i]); 
      } 
      catch (ArithmeticException exc) { 
        // catch the exception 
        System.out.println("Can't divide by Zero!"); 
      } 
      catch (ArrayIndexOutOfBoundsException exc) { 
        // catch the exception 
        System.out.println("No matching element found."); 
      } 
      catch (NonIntResultException exc) { 
        System.out.println(exc); 
      } 
    } 
  } 
}

listing 15
/*  
    Project 9-1 
 
    Add exception handling to the queue classes. 
*/
 
// An exception for queue-full errors. 
class QueueFullException extends Exception { 
  int size; 
 
  QueueFullException(int s) { size = s; } 
 
  public String toString() { 
   return "\nQueue is full. Maximum size is " + 
          size; 
  } 
} 
 
// An exception for queue-empty errors. 
class QueueEmptyException extends Exception { 
 
  public String toString() { 
   return "\nQueue is empty."; 
  } 
}

listing 16
// A fixed-size queue class for characters that uses exceptions. 
class FixedQueue implements ICharQ {     
  private char q[]; // this array holds the queue     
  private int putloc, getloc; // the put and get indices     
     
  // Construct an empty queue given its size.    
  public FixedQueue(int size) {  
    q = new char[size+1]; // allocate memory for queue     
    putloc = getloc = 0;     
  }     
    
  // Put a characer into the queue.     
  public void put(char ch) 
    throws QueueFullException {     
 
    if(putloc==q.length-1)  
      throw new QueueFullException(q.length-1); 
         
    putloc++;     
    q[putloc] = ch;     
  }     
     
  // Get a character from the queue.    
  public char get() 
    throws QueueEmptyException {     
 
    if(getloc == putloc)  
      throw new QueueEmptyException(); 
       
    getloc++;     
    return q[getloc];     
  }     
}

listing 17
// Demonstrate the queue exceptions.     
class QExcDemo {     
  public static void main(String args[]) {     
    FixedQueue q = new FixedQueue(10);     
    char ch;     
    int i;     
     
    try {  
      // overrun the queue 
      for(i=0; i < 11; i++) { 
        System.out.print("Attempting to store : " + 
                         (char) ('A' + i)); 
        q.put((char) ('A' + i));     
        System.out.println(" -- OK"); 
      } 
      System.out.println(); 
    } 
    catch (QueueFullException exc) { 
      System.out.println(exc); 
    } 
    System.out.println(); 
    
    try { 
      // over-empty the queue 
      for(i=0; i < 11; i++) {      
        System.out.print("Getting next char: "); 
        ch = q.get();     
        System.out.println(ch);     
      } 
    } 
    catch (QueueEmptyException exc) { 
      System.out.println(exc); 
    }  
  }     
}

listing 18
// A character queue interface that throws exceptions.  
public interface ICharQ {     
  // Put a characer into the queue.     
  void put(char ch) throws QueueFullException;  
  
  // Get a character from the queue.    
  char get() throws QueueEmptyException;  
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
777a∨成人精品桃花网| 亚洲欧美在线aaa| 色诱视频网站一区| 国产精品综合视频| 色狠狠av一区二区三区| 亚洲午夜电影在线| 粉嫩av亚洲一区二区图片| 成人v精品蜜桃久久一区| 亚洲一区在线观看视频| 亚洲国产美女搞黄色| 国产一区二区三区久久久| 日韩av电影免费观看高清完整版在线观看| 亚洲一区二区三区在线看| 欧美日韩大陆一区二区| 欧美日韩成人一区二区| 91精品蜜臀在线一区尤物| 欧美一区二区三区爱爱| 精品国产自在久精品国产| 久久久久国产精品麻豆ai换脸 | 免费成人在线观看视频| 九色综合国产一区二区三区| 国产乱子伦一区二区三区国色天香| 国产一区二区三区日韩| 成人精品视频一区二区三区 | 欧美va亚洲va在线观看蝴蝶网| 精品国产伦一区二区三区免费| 国产欧美一区二区在线| 亚洲视频狠狠干| 奇米四色…亚洲| 成人综合在线网站| 欧美写真视频网站| 欧美本精品男人aⅴ天堂| 国产精品久久久久久久浪潮网站| 一区二区高清视频在线观看| 国产精品久久久久婷婷| 国产一区中文字幕| 午夜私人影院久久久久| 久久99精品久久久久久| 99热这里都是精品| 欧美一区二区三区在线观看视频| 国产亚洲精久久久久久| 亚洲综合在线免费观看| 韩日欧美一区二区三区| 色综合久久久网| 日韩欧美国产综合一区| 亚洲欧美国产高清| 狠狠色丁香久久婷婷综合_中| 色综合久久综合网欧美综合网| 欧美一二三区在线观看| 国产精品区一区二区三区| 午夜精品福利一区二区三区av | 91黄色激情网站| 精品国产99国产精品| 亚洲激情自拍偷拍| 丁香天五香天堂综合| 亚洲高清在线视频| 亚洲国产cao| 国产精品99久久久久久有的能看 | 亚欧色一区w666天堂| 国产老肥熟一区二区三区| 欧美系列亚洲系列| 激情六月婷婷久久| 日韩激情一二三区| 国产99精品国产| 5月丁香婷婷综合| ...av二区三区久久精品| 美女脱光内衣内裤视频久久网站| 91成人在线精品| 中文字幕精品一区| 精品一二线国产| 欧美精品电影在线播放| 亚洲精品美腿丝袜| 北条麻妃国产九九精品视频| 久久日韩粉嫩一区二区三区| 日韩二区在线观看| 欧美日韩一二三| 亚洲老司机在线| 日韩一级高清毛片| 日韩一区二区三区在线| 国产亚洲成aⅴ人片在线观看| 一区二区三区在线高清| 韩国一区二区在线观看| 欧美一区在线视频| 香蕉久久一区二区不卡无毒影院| 亚洲欧美国产高清| 豆国产96在线|亚洲| 国产精品美女久久久久aⅴ| 久久久蜜桃精品| 中文字幕一区二区三区在线不卡 | 久久久久国产精品人| 日本aⅴ亚洲精品中文乱码| 日韩欧美123| 国产精品毛片久久久久久| 精品成人免费观看| 国产日韩高清在线| 日本道精品一区二区三区| 亚洲一区二区三区在线| 欧美mv日韩mv国产| 成人性生交大片免费看视频在线| 欧美日韩另类国产亚洲欧美一级| 国产精品久久看| 久久这里只有精品6| 亚洲成年人网站在线观看| 亚洲午夜精品网| 午夜av区久久| 亚洲免费视频中文字幕| 午夜精品福利一区二区三区av | 国产精品国产三级国产| 国产麻豆精品95视频| 久久综合精品国产一区二区三区| 韩国三级电影一区二区| 26uuu另类欧美亚洲曰本| 国产乱码精品一区二区三区五月婷| www亚洲一区| 国产aⅴ综合色| 国产精品国产三级国产aⅴ无密码| 成人在线一区二区三区| 亚洲视频免费看| 欧美私模裸体表演在线观看| 午夜激情久久久| 精品久久国产字幕高潮| 国产精品1区二区.| 国产精品国产精品国产专区不蜜 | 久久亚区不卡日本| 粉嫩av一区二区三区在线播放| 中文字幕一区二区三区在线播放| 91一区在线观看| 欧美一区二区成人| 国产精品一区二区黑丝| 日韩国产精品久久| 国产视频一区二区三区在线观看| 国产精品综合一区二区| 日本韩国欧美一区二区三区| 高清国产一区二区| 91麻豆精品国产91久久久资源速度| 久久精品在线免费观看| 欧美激情一区二区三区蜜桃视频 | 69久久99精品久久久久婷婷 | 久久九九影视网| 国内久久婷婷综合| 国产精品免费av| 欧美日韩在线不卡| 《视频一区视频二区| 99久久99久久免费精品蜜臀| 91成人免费网站| 春色校园综合激情亚洲| 国产精品久久久久影视| 亚洲国产精品久久人人爱蜜臀| 在线电影国产精品| av中文字幕不卡| 一区二区三区在线看| 久久国产精品第一页| 91成人在线精品| 国产精品伦一区二区三级视频| 久久99久久精品欧美| 免费的成人av| 3atv在线一区二区三区| 国产成人精品免费在线| 中文字幕日韩一区| 成人免费一区二区三区视频| 亚洲综合一二三区| 亚洲综合色自拍一区| 国内外精品视频| 中文字幕日韩av资源站| 欧美一级欧美三级| 亚洲色大成网站www久久九九| 欧美一区二区三区影视| 粉嫩一区二区三区性色av| 亚洲欧洲日本在线| 久久嫩草精品久久久久| 成人a免费在线看| 中文字幕色av一区二区三区| 麻豆91免费看| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 一区在线观看视频| 精品国产乱码久久久久久牛牛 | 五月天激情小说综合| 91久久精品国产91性色tv | 欧美日韩国产综合一区二区| 亚洲欧美偷拍另类a∨色屁股| 精品国产乱子伦一区| 国精品**一区二区三区在线蜜桃| 欧美一区二区福利视频| 91久久免费观看| 日韩精品影音先锋| 91精品蜜臀在线一区尤物| 毛片av一区二区三区| 午夜久久电影网| 国产日韩一级二级三级| 国产精品综合视频| 欧美日韩成人激情| 亚洲一二三四在线| 欧美va天堂va视频va在线| 色综合欧美在线| 九色porny丨国产精品| 国产一区二区按摩在线观看| 热久久一区二区| 免费高清在线一区| 亚洲高清中文字幕| 国产在线精品视频|