Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. public static void main(String[] args) {
  2. try{
  3. processMessage();
  4. }catch(Exception E){
  5. E.printStackTrace();
  6. }
  7.  
  8. }
  9.  
  10. private static void processMessage() throws Exception{
  11. String transNbr = "";
  12. try{
  13. transNbr = "2345";
  14. throw new Exception();
  15. }catch(Exception E){
  16. if(!transNbr.equals("")){
  17. //stack trace originates from here, not from actual exception
  18. throw new Exception("transction: " + transNbr);
  19. }else{
  20. //stack trace gets passed correctly but no custom message available
  21. throw E;
  22. }
  23. }
  24. }
  25.  
  26. throw new Exception("transction: " + transNbr, E);
  27.  
  28. throw new TransactionProblemException(transNbr, originalException);
  29.  
  30. TransactionProblemException : transNbr
  31. at ...
  32. at ...
  33. caused by OriginalException ...
  34. at ...
  35. at ...
  36.  
  37. try{
  38. ...
  39. }catch(Exception E){
  40. if(!transNbr.equals("")){
  41. throw new Exception("transction: " + transNbr, E);
  42. }
  43. ...
  44. }
  45.  
  46. if (pass.length() < minPassLength)
  47. throw new InvalidPassException("The password provided is too short");
  48. } catch (NullPointerException e) {
  49. throw new InvalidPassException("No password provided", e);
  50. }
  51.  
  52.  
  53. // A custom business exception
  54. class InvalidPassException extends Exception {
  55.  
  56. InvalidPassException() {
  57.  
  58. }
  59.  
  60. InvalidPassException(String message) {
  61. super(message);
  62. }
  63. InvalidPassException(String message, Throwable cause) {
  64. super(message, cause);
  65. }
  66.  
  67. public class MyNullPointException extends NullPointerException {
  68.  
  69. private ExceptionCodes exceptionCodesCode;
  70.  
  71. public MyNullPointException(ExceptionCodes code) {
  72. this.exceptionCodesCode=code;
  73. }
  74. @Override
  75. public String getMessage() {
  76. return exceptionCodesCode.getCode();
  77. }
  78.  
  79.  
  80. public class enum ExceptionCodes {
  81. COULD_NOT_SAVE_RECORD ("cityId:001(could.not.save.record)"),
  82. NULL_POINT_EXCEPTION_RECORD ("cityId:002(null.point.exception.record)"),
  83. COULD_NOT_DELETE_RECORD ("cityId:003(could.not.delete.record)");
  84.  
  85. private String code;
  86.  
  87. private ExceptionCodes(String code) {
  88. this.code = code;
  89. }
  90.  
  91. public String getCode() {
  92. return code;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement