-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from Flamme1004K/item69
[#69][2κΈ°] μμΈλ μ§μ§ μμΈ μν©μλ§ μ¬μ©νλΌ
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
10μ₯/69_μμΈλ_μ§μ§_μμΈ_μν©μλ§_μ¬μ©νλΌ_κΉνμ€.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Item69 μμΈλ μ§μ§ μμΈ μν©μλ§ μ¬μ©νλΌ | ||
|
||
try { | ||
int i = 0; | ||
while(true) { | ||
range[i++].climb() | ||
} | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
} | ||
|
||
ν΄λΉ μ½λμ λ¬Έμ μ μ 무μμΌκΉ? | ||
- ν΄λΉ μ½λλ 무μ¨μΌμ νλ μ½λμΈμ§ μ μκ° μλ€. | ||
- 무ν루νλ₯Ό λλ€κ° λ°°μ΄μ λμ λλ¬ν΄ ArrayIndexOutOfBoundsExceptionμ΄ λ°μν΄μΌ λμ΄λλ€. | ||
|
||
> 첫 λ²μ§Έ μμμμλ μ Exceptionμ λμ Έμ€¬μκΉ? λ°λ‘ JVMμμ λ°°μ΄μ μ κ·Όν λλ§λ€ κ²½κ³λ₯Ό λμ§ μλμ§ κ²μ¬νλλ°, μΌλ°μ μΈ λ°λ³΅λ¬Έλ λ°°μ΄ κ²½κ³μ λλ¬νλ©΄ μ’ λ£λλ€λ ν¬λ§μ λμ Έμ‘μ κ²μ΄λΌκ³ , μ± μμ λ§ν΄μ€λ€. | ||
> νμ§λ§, μ± μμλ μΈκ°μ§λ©΄μμ μλͺ» λ μΆλ‘ μ΄λΌκ³ νλ€. | ||
> 1. μμΈλ μμΈ μν©μ μΈ μ©λλ‘ μ€κ³λμμΌλ―λ‘ μμΈμμλ μ΅μ νμ λ³λ‘ μ κ²½ μ°μ§ μμμ κ°λ₯μ±μ΄ ν¬λ€. | ||
> 2. μ½λλ₯Ό try-catchλΈλ‘ μμ λ£μΌλ©΄ JVMμ΄ μ μ©ν μ μλ μ΅μ νκ° μ ν λλ€. | ||
> 3. λ°°μ΄μ μννλ νμ€ κ΄μ©κ΅¬λ μμ κ±±μ ν μ€λ³΅ κ²μ¬λ₯Ό μννμ§ μλλ€. JVMμ΄ μμμ μ΅μ νν΄ μμ μ€λ€. | ||
|
||
ν΄λΉ μ½λλ₯Ό λ€μ 리ν©ν λ§ νλ€λ©΄, | ||
|
||
for (Mountain m : range) { | ||
m.climb(); | ||
} | ||
|
||
μλμ κ°μ μ₯μ μ κ°μ§κ² λλ€. | ||
- 무μ¨μΌμ νλ μ½λμΈμ§ μ§κ΄μ μ΄κ² νμΈν μ μλ€. | ||
- forLoopκ° λλλ©΄ ν΄λΉ μ½λλ λλκΈ° λλ¬Έμ λΆνμν Exceptionμ λμ§ νμκ° μλ€. | ||
|
||
μλ² μμ΄ν μ λ°λ‘ μ₯μ μ€μ λλ²μ§Έμ ν΄λΉνλ Exceptionμ μ¬λ°λ₯Έ μ°μμ λν΄ 2κ°μ§ νλͺ©μΌλ‘ μ 리νλ©° λλ΄κ³ μλ€. | ||
|
||
1. μμΈλ μ€μ§ μμΈ μν©μμλ§ μ¨μΌ νλ€. μ λλ‘ μ²«λ²μ§Έ μμμ²λΌ, μΌμμ μΈ μ μ΄ νλ¦μ©μΌλ‘ μ°μ¬μ μλλ€. | ||
2. μ μ€κ³λ APIλΌλ©΄ ν΄λΌμ΄μΈνΈκ° μ μμ μΈ μ μ΄ νλ¦μμ μμΈλ₯Ό μ¬μ©ν μΌμ΄ μκ² ν΄μΌνλ€. |