Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Java Programming/Keywords/throws

From Wikibooks, open books for an open world
<Java Programming |Keywords

throws is a Java keyword. It is used in a method definition to declare the Exceptions to be thrown by the method.

Syntax:

public myMethod()throws MyException1, MyException2{MyException1  ...}

Example:

Computer code
classMyDefinedExceptionextendsException{publicMyDefinedException(Stringstr){super(str);}}publicclassMyClass{publicstaticvoidshowMyName(Stringstr)throwsMyDefinedException{if(str.equals("What is your Name?"))thrownewMyDefinedException("My name is Blah Blah");}publicstaticvoidmain(Stringa[]){try{showMyName("What is your Name?");}catch(MyDefinedExceptionmde){mde.printStackTrace();}}}
Retrieved from "https://en.wikibooks.org/w/index.php?title=Java_Programming/Keywords/throws&oldid=3241583"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp