Thursday, February 25, 2021

Using Hamcrest and valid4j With DBC Techniques To Throw Recoverable Exceptions

Introduction

Input validation is one of the most important concerns  in methods, especially in the case that you have methods calling between classes; consider a case in which you have a class called CALLER that has a method which calls a specific method in CALLEE class:

Java
 

Java
 




x
25


 
1
public class Caller {
2
 
3
    public void calls(Object input){
4
        .
5
        .
6
        Result result=callee.doSomthing();
7
8
        if(result==null){
9
             throw new SomeCallerException();
10
        }
11
        else if(callee.getState()==ONE){
12
            result.doMainJob();
13
        }
14
       else {
15
            throw new AnotherCallerException();
16
       }
17
18
      .
19
      .
20
      . 
21
22
23
    }
24
}
25





from DZone.com Feed https://ift.tt/3dKeEcg

No comments:

Post a Comment