Advertisement
selvalives

Untitled

Aug 27th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. Exception and error handling in java
  2. -unexpected or abnormal event
  3. -belongs to parent class called throwable
  4. -checked exception(must be caught,example File Classes)
  5. and unchecked exception(example 10/0, nothing to be caught)
  6. -try catch finally or try with resources
  7. -refer to slides for information leakage specific to errors
  8.  
  9. errorneous exceptional behaviors
  10. -suppress or ignoring checked exception-
  11. dummy blocks that does nothing but to fullfill the criteria
  12. -disclose error information-printstacktrace
  13. -logging sensitive data
  14. -ensure that logging process should not be disrupted by throwing incorrect exceptions
  15. -use java.util.logging.logger instead of System.err
  16. -for System.exit(), use security manager to check if the caller is valid to invoke the method
  17. -nullpointerexception should not be caught but should be solved, do not solve problem by simply appying nullpointerexception in the catch clause
  18. -code inside finally block can also throw error, so, don't let them to escape but handle them as well
  19.  
  20. dos and donts in error handling
  21. -avoid direct usage of Exception class in the catch block
  22. -avoid printstacktrace
  23. -use logger file to log the error
  24. -do not use same exceptions for different function throws, leads to difficulty in debugging
  25. -cleanup in the finally
  26.  
  27. spring mvc error handling
  28. -controller level exception handler
  29. -add @exceptionhandler annotation
  30. -include the list of exceptions
  31. -implementing handlerexceptionresolver
  32. -override resolveexception method
  33. -global exception handler
  34. -use @controlleradvice annotation with @exceptionhandler for any class
  35. -custom errors mapping
  36. -use @enablewebsecurity annotation and websecurityadapter
  37. struts2 error
  38. -global exception handling
  39. -refer slides for configuration sample
  40. -action level exception handling
  41. -define the class name and action name in the struts.xml file
  42. -refer slides for configuration example
  43. -logging
  44. -for logging the exception, add an interceptor to struts.xml file
  45. -refer slides for configuration example
  46. best practices for error handling
  47. -throw relevant error to its interface
  48. -specify the reason for the exception
  49. -encapsulate the error received from another function
  50. -use getCause to find the root exception
  51. -catch errors specifically so that handling can be done separately and specifically
  52. -create custom error page for all exceptions-no information leakage from default page
  53.  
  54. logging in java
  55. -provided by java.util.logging
  56. -LOGGER->FORMATTER-HANDLER(Apache Commons Logging,Log4J)
  57. logging with log4j
  58. -contains levels such as DEBUG,INFO,WARN,ERROR,FATAL,OFF
  59. secure coding in logging
  60. -don't log and then throw errors
  61. -do either one only
  62. -parameterized logging using SLF4J, don't use + for merging informations
  63. -log exceptions in proper order
  64. best practices in logging
  65. -logging can increase IO operations, so , log debug messages inside isdebugenabled() block
  66. -use log4j, logging levels can be changed without restarting the application
  67. -do not log sensitive data when logging in production enviroment
  68. -do appropriate level for every logging messages
  69. -specify the format for logger, which includes thread name and class name
  70. -specify the date with the messages
  71. -use code level prefix to indicate which part of the code is
  72. printing the message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement