Creating And Using Exceptions tkorinphotmail com Kinds of

  • Slides: 10
Download presentation
Creating And Using Exceptions �������� ����������������� (tkorinp@hotmail. com)

Creating And Using Exceptions �������� ����������������� (tkorinp@hotmail. com)

Kinds of Exception • ��������� (normal exceptions and run time exceptions) • Subclass java.

Kinds of Exception • ��������� (normal exceptions and run time exceptions) • Subclass java. lang. Exception – ����������� ��� – Throws try/catch block – ��������� ������� IO errors • Subclass java. lang. Runtime. Exception – ������������ ����� – ���������� Throws try/catch block

Extending the Exception Class • ���������� • “Unknown. Client. Exception” import java. lang. Exception;

Extending the Exception Class • ���������� • “Unknown. Client. Exception” import java. lang. Exception; • ������������� class Unknown. Client. Exception extends Exception { �������� /** * Constructor * * @param p. Message description of exception */ Unknown. Client. Exception (String p. Message) { super(p. Message); } }

Extending the Exception Class • API ���������� – IOException • • Char. Conversion. Exception

Extending the Exception Class • API ���������� – IOException • • Char. Conversion. Exception EOFException File. Not. Found. Exception Object. Stream. Exception – Null. Pointer. Exception – Printer. Exception – SQLexception

Throwing Exceptions • ���������������� if (found. Client != null) { return found. Client; }

Throwing Exceptions • ���������������� if (found. Client != null) { return found. Client; } else { throw new Unknown. Client. Exception("Book. Of. Clients. get. Client(): unknown client ID: " + p. Client. ID); }

Catching Exceptions • ����� • ���������� � ����� – ���� try / catch block

Catching Exceptions • ����� • ���������� � ����� – ���� try / catch block try { Client c = list. Of. Clients. get. Client(client. ID) ; c. determine. Credit. Rating(); } catch (Unknown. Client. Exception uce) { System. out. println("INTERNAL ERROR IN Bank. Manager. award. Loan()n"+ "Exception details: " + uce); }

Exception object

Exception object