block can have more than one catch block try and catch block comes in pair

Block can have more than one catch block try and

This preview shows page 35 - 43 out of 43 pages.

block can have more than one catch( ) block. try and catch() block comes in pair. There must be at least one catch() block for every try block. If there is a finally , there should be one for every try block. Multiple finally block is strictly prohibited. >> Lesson 5 4 4
Image of page 35

Subscribe to view the full document.

MAKING RISK Lesson 6 >> Lesson 6 4 5
Image of page 36
Your Own Exception You can create your own exception. It will be handled the same way as other exception. You can do so by extending from class Exception . Then, you have to throw the exception yourself. >> Lesson 6 4 6
Image of page 37

Subscribe to view the full document.

Consider This The Bank need to check if the PropertyOwner has sufficient balance to purchase a property. If balance is not sufficient, an exception should thrown. Immediately, bank will offer for loan or mortgage. Let’s create an exception class for this. >> Lesson 6 4 7
Image of page 38
Exception Design The exception class must extends to class Exception . >> Lesson 6 4 8 Exception InsufficientBalanceException - message = “Insufficient Balance” : String + InsufficientBalance() + offerLoan( acceptance:boolean):void
Image of page 39

Subscribe to view the full document.

Implementing Exception Design public class InsufficentBalanceException extends Exception { private final String message = “ Insufficient Balance”; public InsufficentBalanceException() { super(message); } public void offerLoan(boolean accceptance) { /* insert implementation here */ } } >> Lesson 6 4 9
Image of page 40
Player and PropertyOwner >> Lesson 6 5 0 PropertyOwner -ownedProperty:Property[ ] +buyProperty(property:Property):boolean +sellProperty(property:Property):boolean Player #name: String #totalCashInHand: double #selectedToken : Token +Player(name:String, selectedToken:Token) +updatetotalCashInHand(amount:double):void InsufficientBalanceException - message = “Insufficient Balance” : String + InsufficientBalance() + offerLoan( acceptance:boolean):void buyProperty will throw InsufficeientBalanceException
Image of page 41

Subscribe to view the full document.

Making Risky Method public class PropertyOwner extends Player { /* Assume other members have been implemented */ public boolean buyProperty(Property property) throws InssufficentBalanceException { double estimatedBalance = totalCashInHand property.getSellPrice(); if (estimatedBalance < 1) throw new InsufficientBalance(); return true; } } >> Lesson 6 5 1 Declaring exception to be thrown Throwing new exception object
Image of page 42
THAT’S WRAP FOR TODAY See You in the Next Class >> Lecture 8 5 2
Image of page 43

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes