Java

throw vs throws

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

throw e hedh një përjashtim tani (throw new IllegalArgumentException(...)), ndërsa throws në kokën e metodës paralajmëron që metoda mund të hedhë një përjashtim të caktuar, dhe kush e thërret duhet ta trajtojë.

EnglishEN

throw throws an exception right now (throw new IllegalArgumentException(...)), while throws in a method's signature warns that the method may throw a certain exception, and the caller has to handle it.

Si ta mendosh

throws është tabela „Kujdes, dysheme e lagur“; throw është vetë rrëshqitja.

Lexoje në anglisht

throws is the “Caution: wet floor” sign; throw is the actual slip.

Shembull kodijava

void lexo(String f) throws IOException {
    if (f.isEmpty()) throw new IllegalArgumentException("Emër bosh");
}

Terma të lidhur