• ·Î±×ÀÎ ÇÔ ÇØº¸²ô³ª?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    C++ ÇÁ·Î±×·¡¸Ó Java Essential ¾Ë±â #1
    Last Modify : 13 January, 2011(01:09)

    À̹ø¿¡´Â ¿¹¿Ü󸮿¡ ´ëÇØ¼­ ¾Ë¾Æ º¸°Ú´Ù.

     

    ÇÔ¼öÇü ÇÁ·Î±×·¥ÀÇ °æ¿ì È£Ãâ ÈÄ ¿À·ù ¹ß»ý½Ã goto ¸¦ ÀÌ¿ëÇϰųª ¹Ù·Î return ÇÏ¿© È£ÃâÇÑ ÇÔ¼ö·Î ¹Ù·Î Àü´ÞÀ» ÇÏ°Ô µÇ´Âµ¥ C++ °ú java¿¡¼­´Â try... catch ¸¦ ÀÌ¿ëÇÏ°Ô µÇ´Âµ¥ º¸Åë try{ } ³»¿¡ ¿À·ù°¡ ¹ß»ýÇϸé throw ¸¦ ¹ß»ý ½ÃÄÑ catch ¿¡¼­ ¿À·ù¸¦ ÀÎÁöÇÏ°Ô µÈ´Ù.

     

     

    ¿À·ù´Â Å©°Ô Error ¿Í Exception À¸·Î ±¸ºÐµÇ¸ç Error ÀÇ °æ¿ì ½É°¢ÇÑ ¿À·ù (out of memory or stack over flow) ÀÏ °æ¿ì¿¡ ¹ß»ýÇϰí Exception ÀÇ °æ¿ì ¼ö½ÀÀÌ °¡´ÉÇÑ ÀϹÝÀûÀÎ ¿À·ù¸¦ ¹ß»ýÇÒ ¶§ ¹ß»ýÇÏ°Ô µÈ´Ù.

     

    ¸ÕÀú °¢°¢ÀÇ exception ¿¡ ´ëÇØ¼­ ¾Ë¾Æº¸ÀÚ.. ÇØ´ç ³»¿ëÀº java.lang ¿¡¼­ exception Ç׸ñ¿¡¼­ È®ÀÎ ÇÒ¼ö ÀÖ´Ù.

     

     

    ArithmeticException 
     »ê¼ú ¿À·ù°¡ ¹ß»ýµÇ¾úÀ» ¶§ throw ÇÑ´Ù ÁÖ·Î 0À» 0À¸·Î ³ª´­ ¶§ ¹ß»ýÇÑ´Ù.


    ArrayIndexOutOfBoundsException 
     À߸øµÈ À妽º¸¦ »ç¿ëÇØ ¹è¿­À» À߸ø ¿¢¼­½º ÇßÀ» ¶§ ¹ß»ýÇÑ´Ù.


    ArrayStoreException 
     À߸øµÈ ÇüÅÂÀÇ °´Ã¼¸¦ ¹è¿­¿¡ Æ÷ÇÔÇÏ·Á°í ÇÒ ¶§ ¹ß»ýÇÑ´Ù.


    ClassCastException 
     ¼­·Î °ü°è°¡ ¾ø´Â Ŭ·¡½º¸¦ ij½ºÆÃ ÇÏ·Á°í ÇÒ ¶§ ¹ß»ýÇÑ´Ù.


    ClassNotFoundException 
     È£ÃâÇÑ Å¬·¡½º°¡ Á¸ÀçÇÏÁö ¾ÊÀ» °æ¿ì ¹ß»ýÇÑ´Ù.

     
    CloneNotSupportedException 
     °´Ã¼¸¦ º¹Á¦Çϱâ À§Çؼ­ Object Ŭ·¡½ºÀÇ clone ¸¦ È£ÃâÇÏ¿´Áö¸¸ °´Ã¼ÀÇ Å¬·¡½º°¡ Cloneable ÀÎÅÍÆäÀ̽º¸¦ °¡Áö°í ÀÖÁö ¾ÊÀ» °æ¿ì ¹ß»ýÇÑ´Ù.


    EnumConstantNotPresentException 
     ¾îÇø®ÄÉÀ̼ÇÀÌ À̸§¿¡ ÀÇÇØ enum À» È£ÃâÇϰųª? Á¸ÀçÇÏÁö ¾Ê´Â enum ¸¦ È£ÃâÇÒ ¶§ ¹ß»ý


    IllegalAccessException 
     ¾îÇø®ÄÉÀ̼ÇÀÌ ¹è¿­ ÀÌ¿ÜÀÇ ÀνºÅϽº¸¦ »ý¼ºÇϰųª, Çʵ带 ¼³Á¤, ¸Þ¼Òµå È£ÃâÀ» ½ÃµµÇßÀ» °æ¿ì ¹ß»ý


    IllegalArgumentException 
     À߸øµÈ Àμö, ¶Ç´Â ¿Ã¹Ù¸£Áö ¾Ê´Â Àμö¸¦ ¸Þ¼Òµå¿¡ Àü´ÞÇÒ°æ¿ì ¹ß»ý


    IllegalMonitorStateException 
     ¸ð´ÏÅ͸¦ °¡ÁöÁö ¾ÊÀº ¾²·¹µå°¡ ¸ð´ÏÅ͸¦ ±â´Ù¸±¶§ ¹ß»ý (¸ð´ÏÅͰ¡ ¸ÓÀÓ?)


    IllegalStateException 
     ¿Ã¹Ù¸£Áö ¾ÊÀ» ¶§¿¡ ¸Þ¼Òµå°¡ ºÒ·ÁÁú ¶§ ¹ß»ý


    IllegalThreadStateException 
     ¿ä±¸µÈ ¿ÀÆÛ·¹À̼ǿ¡ ´ëÇØ¼­ THREAD »óŰ¡ ¿Ã¹Ù¸£Áö ¾ÊÀº °ÍÀ» ³ªÅ¸³¾ ¶§ ¹ß»ý


    IndexOutOfBoundsException 
     ¾î¶² Á¾·ùÀÇ À妽º(¹è¿­, ij¸¯ÅÍ ¶óÀÎ, º¤Å͵î)°¡ ¹üÀ§¸¦ ³Ñ¾î¼± °ÍÀ» Ç¥ÇöÇÏ·Á°í ÇÒ ¶§ ¹ß»ý


    InstantiationException 
     Å¬·¡½º¸¦ ÀνºÅϽº ÇÏ·Á°í ÇÒ ¶§ ÁöÁ¤µÈ °´Ã¼¸¦ ÀνºÅϽº ÇÒ ¼ö ¾øÀ» ¶§ ¹ß»ý ÁÖ·Î abstract class ¸¦ ÀνºÅϽº Çϰųª interface ¸¦ ÀνºÅϽºÇÏ·Á°í ÇÒ °æ¿ì ¹ß»ý


    InterruptedException 
     wait ³ª sleep ¸Þ¼Òµå¸¦ »ç¿ëÇØ thread °¡ ´ë±â »óÅ¿¡ µé¾î°¬´Ù°¡ ±ú¾î³ªÁö ¸øÇÑ »óÅÂÀ» ¶§ ¹ß»ý


    NegativeArraySizeException 
     ¹è¿­ÀÇ Å©±â¸¦ -(À½¼ö) ·Î ÁöÁ¤ÇÒ ¶§ ¹ß»ý


    NoSuchFieldException 
     Á¸ÀçÇÏÁö ¾Ê´Â Çʵ带 ÂüÁ¶ÇÏ·Á°í ÇÒ ¶§ ¹ß»ý


    NoSuchMethodException 
     Á¸ÀçÇÏÁö ¾Ê´Â ¸Þ¼Òµå¸¦ ÂüÁ¶ÇÏ·Á°í ÇÒ ¶§ ¹ß»ý


    NullPointerException 
     »ç¿ëÇÏ·Á°í ÇÏ´ø °´Ã¼°¡ null ÀÏ °æ¿ì ¹ß»ý


    NumberFormatException 
     ¹®ÀÚ¿­À» ¼ýÀÚ·Î º¯°æÇÏ·Á°í Çϴµ¥ ¹®ÀÚ¿­À» ¼ýÀÚ·Î º¯°æÇÒ ¼ö ¾øÀ» ¶§

     

    SecurityException 
     º¸¿Ï°ü·ÃÇØ À§¹ÝÀ» ÇßÀ» ¶§ ¹ß»ý


    StringIndexOutOfBoundsException 
     ¹®ÀÚ¿­¿¡ Àüü ±æÀ̺¸´Ù Å« °ªÀ» ÀÌ¿ëÇÏ·ÁÇÒ ¶§ (¿¹ substring, charAt) ¹ß»ý


    TypeNotPresentException 
     »ç¿ëÇÏ·Á´Â ŸÀÔÀÌ Á¤ÀǵÇÁö ¾Ê¾ÒÀ» °æ¿ì ¹ß»ý


    UnsupportedOperationException
     ±¸ÇöµÇÁö ¾Ê´Â ¸Þ¼Òµå¸¦ È£ÃâÇÏ·Á°í ÇÒ ¶§ ¹ß»ýÇÑ´Ù.

     


    private Vector vector;
    private static final int SIZE = 10;

    PrintWriter out = null;

    try {
        System.out.println("Entered try statement");
        out = new PrintWriter(new FileWriter("OutFile.txt"));
        for (int i = 0; i < SIZE; i++) {
            out.println("Value at: " + i + " = " + vector.elementAt(i));
        }
    }
    catch and finally statements . . .

    À§ÀÇ ÄÚµå´Â vector ÀÇ ³»¿ëÀ» OutFile.txt ¿¡ ÀÔ·ÂÇÏ´Â °£´ÜÇÑ ÄÚµå·Î ¸¸¾à ÀÌ »óȲ¿¡ ÆÄÀÏÀÌ Á¸ÀçÇÏÁö ¾Ê¾Æ ¿À·ù°¡ ¹ß»ýÇÑ´Ù¸é´ÙÀ½Ã³·³ Äڵ带 »ý¼ºÇؾßÇÒ °ÍÀÌ´Ù.


    } catch (FileNotFoundException e) {
        System.err.println("FileNotFoundException: " + e.getMessage());
        throw new SampleException(e);
        
    } catch (IOException e) {
        System.err.println("Caught IOException: " + e.getMessage());
    }


    À§ÀÇ ÄÚµåó·³ catch ´Â °è¼ÓÇØ¼­ »ý¼ºÀ» ÇØ¼­ ¸¸µé ¼ö ÀÖ°í ¸¶Áö¸·À¸·Î java ¿¡¼­´Â c++ °ú´Â ´Ù¸£°Ô finally ¶ó´Â Ç׸ñÀÌ Ãß°¡ÀûÀ¸·Î Á¸ÀçÇϴµ¥ ¸®¼Ò½º¸¦ ÇØÁ¦°¡ ÇÊ¿äÇÒ ¶§ µî·ÏÀ» ÇÏ´Â °÷ÀÌ´Ù.  ¾Æ·¡ÀÇ ÄÚµåó·³ Á¤»óÀûÀ¸·Î Á¾·áÇÏ¿´°Å³ª ¿À·ù°¡ ¹ß»ýÇÏ¿´À» ¶§ out.close() ¸¦ ÇØ¾ßµÇ´Âµ¥ try, catch ¾Æ·¡Ã³·³ Áߺ¹ Äڵ尡 ¹ß»ýÇϹǷΠÀ̸¦ º¸¿ÏÇϱâ À§Çؼ­ finally ¿¡ out.close() ¸¦ È£ÃâÇØ ÄÚµå Áߺ¹À» ÇÇÇÒ ¼ö ÀÖ´Ù.

    try {
        
        out.close();       //Don't do this; it duplicates code. 
        
    } catch (FileNotFoundException e) {

        out.close();       //Don't do this; it duplicates code.
        System.err.println("Caught: FileNotFoundException: " + e.getMessage());
        throw new RuntimeException(e);

    } catch (IOException e) {
        
     System.err.println("Caught IOException: " + e.getMessage());

    }

    ÀÚ À§ÀÇ ¸ðµç °æ¿ìÀÇ ¼ö¸¦ Àû¿ëÇÑ ¿Ã¹Ù¸¥ ¿Ï¼ºµÈ ¼Ò½º¸¦ º¸µµ·Ï ÇÏÀÚ.

    public void writeList()
    {
        PrintWriter out = null;

        try
     {
            System.out.println("Entering try statement");
            out = new PrintWriter(new FileWriter("OutFile.txt"));
        
      for (int i = 0; i < SIZE; i++)
      {
       out.println("Value at: " + i + " = " + vector.elementAt(i));
      }
        }
     catch (ArrayIndexOutOfBoundsException e)
     {
             System.err.println("Caught " + "ArrayIndexOutOfBoundsException: " +   e.getMessage());
        }
     catch (IOException e)
     {
             System.err.println("Caught IOException: " +  e.getMessage());
        }
     finally
     {
            if (out != null)
      {
       System.out.println("Closing PrintWriter");
                out.close();
      
            }
            else
      {
       System.out.println("PrintWriter not open");
            }
        }
    }

    ArrayIndexOutOfBoundsException ´Â ¹éÅÍÀÇ ¹üÀ§¸¦ ¹þ¾î³µÀ» ¶§ ¹ß»ýµÇ´Â ¿À·ù À̰í, IOException ´Â ÀϹÝÀûÀÎ Input/Output ¿À·ù »óȲÀÌ´Ù.

    System.out ÀÌ Á¸ÀçÇÒ °æ¿ì finally ¿¡¼­ file descriptor ¸¦ Á¦°ÅÇÏ´Â °ÍÀÌ´Ù. +

     

     

     

    Ãß°¡ ¸µÅ©

    http://onjava.com/pub/a/onjava/2003/11/19/exceptions.html

     

    http://kaludin.egloos.com/2255332

     

    http://mysnyc.tistory.com/37


    Comment


    ÀÔ·ÂÇÏ3 1524694139



    Locations of visitors to this page