Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- try{
- processMessage();
- }catch(Exception E){
- E.printStackTrace();
- }
- }
- private static void processMessage() throws Exception{
- String transNbr = "";
- try{
- transNbr = "2345";
- throw new Exception();
- }catch(Exception E){
- if(!transNbr.equals("")){
- //stack trace originates from here, not from actual exception
- throw new Exception("transction: " + transNbr);
- }else{
- //stack trace gets passed correctly but no custom message available
- throw E;
- }
- }
- }
- throw new Exception("transction: " + transNbr, E);
- throw new TransactionProblemException(transNbr, originalException);
- TransactionProblemException : transNbr
- at ...
- at ...
- caused by OriginalException ...
- at ...
- at ...
- try{
- ...
- }catch(Exception E){
- if(!transNbr.equals("")){
- throw new Exception("transction: " + transNbr, E);
- }
- ...
- }
- if (pass.length() < minPassLength)
- throw new InvalidPassException("The password provided is too short");
- } catch (NullPointerException e) {
- throw new InvalidPassException("No password provided", e);
- }
- // A custom business exception
- class InvalidPassException extends Exception {
- InvalidPassException() {
- }
- InvalidPassException(String message) {
- super(message);
- }
- InvalidPassException(String message, Throwable cause) {
- super(message, cause);
- }
- public class MyNullPointException extends NullPointerException {
- private ExceptionCodes exceptionCodesCode;
- public MyNullPointException(ExceptionCodes code) {
- this.exceptionCodesCode=code;
- }
- @Override
- public String getMessage() {
- return exceptionCodesCode.getCode();
- }
- public class enum ExceptionCodes {
- COULD_NOT_SAVE_RECORD ("cityId:001(could.not.save.record)"),
- NULL_POINT_EXCEPTION_RECORD ("cityId:002(null.point.exception.record)"),
- COULD_NOT_DELETE_RECORD ("cityId:003(could.not.delete.record)");
- private String code;
- private ExceptionCodes(String code) {
- this.code = code;
- }
- public String getCode() {
- return code;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement