Guest User

Untitled

a guest
Jan 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #outer tryCatch, see 1.
  2. tryCatch({
  3. #user code block
  4. #2a. user specific tryCatch, object "vec" not defined
  5. tryCatch(print(vec),error=function(e) {print("Non-fatal error. Script execution continued.");print(e);})
  6.  
  7. #2b. user specific tryCatch
  8. tryCatch(vec*2)
  9.  
  10. #2c. user specific tryCatch
  11. tryCatch(vec*parameter1, error=function(e) {print("Additional fatal error information. Script execution aborted.");stop(e);})
  12. #end of user code block
  13. },
  14. #outer tryCatch error handler in order to handle fatal errors
  15. error=function(e) {print("Fatal error");print(e);}
  16. )
  17.  
  18. ourError <-
  19. function(original, message, class="ourError")
  20. {
  21. msg <- paste(message, conditionMessage(original), sep="n ")
  22. structure(list(message = msg, call = conditionCall(original)),
  23. class = c(class, class(original)))
  24. }
  25.  
  26. tryCatch(vec*parameter1, error=function(e) {
  27. err <- ourError(e, "addition fatal info; script aborted")
  28. stop(err)
  29. })
  30.  
  31. tryCatch({
  32. tryCatch(stop("oops"), error=function(e) {
  33. err <- ourError(e, "addition fatal info; script aborted",
  34. c("fatal", "ourError"))
  35. stop(err)
  36. })
  37. }, ourError=function(err) {
  38. message("We caught but didn't handle this:n", err)
  39. }, error =function(err) {
  40. message("This one got away: ", err)
  41. })
Add Comment
Please, Sign In to add comment