Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Object doSomething() throws Throwable {
- ...
- }
- public Object doSomething() throws BusinessException {
- if(!hasMinimumbalance())
- {
- throw new InsufficientBalance(ErrorCode);
- }
- }
- public void myMethod() throws Throwable {
- if (x) {
- throw new MyException1();
- }
- if (y) {
- throw new MyException2();
- }
- }
- public void callingMethod() {
- try {
- myMethod();
- }
- catch(Throwable t) {
- if (t instanceof MyException1) {
- // handle exception 1
- }
- else if (t instanceof MyException2) {
- // handle exception 2
- }
- else {
- // handle other exceptions
- }
- }
- }
- public void myMethod() throws MyException1, MyException2 {
- if (x) {
- throw new MyException1();
- }
- if (y) {
- throw new MyException2();
- }
- }
- public void callingMethod() {
- try {
- myMethod();
- }
- catch(MyException1 e) {
- // handle exception 1
- }
- catch(MyException2 e) {
- // handle exception 2
- }
- }
- prvate int parseAmount(String amountValue) {
- int amount;
- try {
- amount = Integer.parseInt(amountValue);
- }
- catch(NumberFormatException e) {
- // default amount
- amount = 0;
- }
- return amount;
- }
- private Customer getCustomer(int customerId) throws ServiceException {
- try {
- return customerService.getCustomer(customerId);
- }
- catch(CustomerServiceSpaghettiTangledException e) {
- throw new ServiceException("Error calling the customer service", e);
- }
- }
Add Comment
Please, Sign In to add comment