<blockquote class=lexical__quote dir=ltr><b><strong class=lexical__textBold style=white-space: pre-wrap;>【Kotlin 入門指南】系列文章目錄:</strong></b><a href=https://bit.ly/3t8awwL><b>://bit.ly/3t8awwL</strong></b></a></blockquote><blockquote class=lexical__quote dir=ltr><b> 線上課程教學影片:</strong></b><a href=https://bit.ly/3qJ5a5Q target=_blank>://bit.ly/3qJ5a5Q</span></a></blockquote><h2 class=lexical__h2 dir=ltr> 拋出例外</span></h2><p class=lexical__paragraph dir=ltr><span style=white-space: pre-wrap;>在 kotlin 中,當我們想要表示,某段程式運行時,發生例外,我們可以透過「throw」關鍵字來拋出對應的例外狀況,例如:</span></p><pre spellcheck=false data-highlight-language=javascript> </span></span><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>(</span><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>)</span><span style=white-space: pre-wrap;> </span><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>{</span><br><span style=white-space: pre-wrap;> </span></span><span style=white-space: pre-wrap;> </span></span><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>(</span>線上教室,發生不可預期錯誤</span><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>)</span><br><span class=lexical__tokenPunctuation style=white-space: pre-wrap;>}</span></pre><p class=lexical__paragraph dir=ltr><span style=white-space: pre-wrap;>輸出資訊視窗</span></p><div class=lexical__image center><div class=lexical__imageWrapper><img src=https://d2a6d2ofes041u.cloudfront.net/resize?compression=6&norotation=true&url=https%3A%2F%2Fimages.vocus.cc%2F7726170f-c87e-4e22-b71f-89d17a8d40d8.png&width=740&sign=euvrEq8-V2Y9yajLGBZ--DkFa-rPGcvEJjLc0qiHi8I data-src=https://d2a6d2ofes041u.cloudfront.net/resize?compression=6&norotation=true&url=https%3A%2F%2Fimages.vocus.cc%2F7726170f-c87e-4e22-b71f-89d17a8d40d8.png&width=740&sign=euvrEq8-V2Y9yajLGBZ--DkFa-rPGcvEJjLc0qiHi8I data-original-src=https://images.vocus.cc/7726170f-c87e-4e22-b71f-89d17a8d40d8.png data-lowquality=true data-loaded=false data-width=1398 data-height=376 onerror=this.onError=null;this.src=this.dataset.originalSrc; alt=image></div><div class=captionTheme__wrapper><p class=captionTheme__paragraph></p></div></div>