μλ°(Java)μμ μμΈ(Exception)λ νλ‘κ·Έλ¨ μ€ν μ€μ λ°μν μ μλ μμμΉ λͺ»ν μν© λλ μ€λ₯λ₯Ό λνλ λλ€.
μ΄λ¬ν μμΈλ νλ‘κ·Έλ¨μ μ μμ μΈ νλ¦μ λ°©ν΄νκ±°λ νλ‘κ·Έλ¨μ΄ λΉμ μμ μΌλ‘ μ’ λ£λ μ μλ μμΈμ΄ λ μ μμ΅λλ€. μλ°μμλ μμΈλ₯Ό μ²λ¦¬νκ³ κ΄λ¦¬νκΈ° μν λ€μν λ©μ»€λμ¦μ΄ μ 곡λ©λλ€.
μμΈ (Exception)
μμΈλ μ£Όλ‘ νλ‘κ·Έλ¨μ μΈλΆ μν©μ΄λ μ¬μ©μ μ λ ₯μ μν΄ λ°μνλ λ¬Έμ λ₯Ό λνλ λλ€. μμΈλ μΌλ°μ μΌλ‘ νλ‘κ·Έλ¨ μ½λμμ μ²λ¦¬ν μ μλ μν©μ΄λ©°, μμΈκ° λ°μνλ©΄ νλ‘κ·Έλ¨μ μμΈλ₯Ό μ μ ν μ²λ¦¬νμ¬ κ³μ μ€νλ μ μμ΅λλ€. μλ°μμλ μμΈλ₯Ό μ²λ¦¬νκΈ° μν try-catch λΈλ‘μ μ¬μ©ν©λλ€. Checked μμΈμ Unchecked μμΈ(λ°νμ μμΈ)λ‘ λλ©λλ€.
1) IOException: Checked μμΈμ μΌμ’ μΌλ‘, μ μΆλ ₯ μμ μ μννλ λμ λ°μν μ μλ μμΈλ₯Ό μ²λ¦¬νλ λ° μ¬μ©
- μ£Όλ‘ μΈλΆ μμμ μ κ·Όν λ λ°μν μ μλ μμΈλ₯Ό μ²λ¦¬νκΈ° μν΄ μ£Όλ‘ νμ©
- νμΌμ μ½κ±°λ μΈ λ νμΌμ΄ μ‘΄μ¬νμ§ μκ±°λ κΆνμ΄ μλ κ²½μ°μ IOExceptionμ΄ λ°μ
- μ»΄νμΌλ¬κ° μμΈ μ²λ¦¬ μ¬λΆλ₯Ό νμΈ (μμΈ μ²λ¦¬ νμ)
2) RuntimeException: Unchecked μμΈμ μμ ν΄λμ€μ λλ€. μ¦, μ»΄νμΌλ¬κ° μμΈ μ²λ¦¬λ₯Ό κ°μ νμ§ μμ΅λλ€.
- νλ‘κ·Έλλ¨Έμ μ€μλ μλͺ»λ μ¬μ©μ κΈ°μΈν μμΈ. μ£Όλ‘ λ Όλ¦¬ μ€λ₯λ μλͺ»λ νλ‘κ·Έλλ° κ΄νμΌλ‘ μΈν μ€λ₯μ ν΄λΉ
- μ»΄νμΌλ¬κ° μμΈ μ²λ¦¬ μ¬λΆ νμΈ νμ§ μμ (μμΈ μ²λ¦¬λ μ ν)
μλ¬ (Error)
μλ¬λ μ£Όλ‘ μμ€ν μ΄λ νκ²½κ³Ό κ΄λ ¨λ μ¬κ°ν λ¬Έμ λ₯Ό λνλ λλ€. μλ¬λ λλΆλΆ νλ‘κ·Έλ¨ μ½λμμ μ§μ μ μΌλ‘ ν΄κ²°ν μ μλ μν©μ λνλ λλ€. μλ₯Ό λ€λ©΄, OutOfMemoryErrorμ κ°μ΄ λ©λͺ¨λ¦¬ λΆμ‘± λ¬Έμ , StackOverflowErrorμ κ°μ΄ μ€ν μ€λ²νλ‘μ° λ¬Έμ λ±μ΄ μ¬κΈ°μ ν΄λΉν©λλ€. μλ¬λ μ£Όλ‘ νλ‘κ·Έλ¨μ λ³΅κ΅¬κ° λΆκ°λ₯ν μν©μ λνλ΄λ©°, λ³΄ν΅ νλ‘κ·Έλ¨ μ’ λ£λ₯Ό μΌκΈ°ν©λλ€.
An exception is an unexpected event that occurs during program execution. Exceptions can be caught and handled by the program. When an exception occurs within a method, it creates an object. This object is called the exception object. It contains information about the exception such as the name and description of the exception and state of the program.
Errors represent irrecoverable conditions such as memory leaks, stack overflow errors etc. Errors are usually beyond the control of the programmer and we should not try to handle errors.
'Programming > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
22 throw & throws (0) | 2024.01.21 |
---|---|
21 Exception handling (0) | 2024.01.21 |
19 Interface (0) | 2024.01.20 |
18 Polymorphism (0) | 2024.01.20 |
17 Abstraction (0) | 2024.01.20 |
λκΈ