for (i in 1:10) {
tryCatch({
print(i)
if (i==6) stop("Urgh, the iphone is in the blender----2 !")
if (i==7) stop("Urgh, the iphone is in the blender !")
if (i==8) warning('The "factorial" function was used')
}, error = function(e) {
cat("ERROR :",conditionMessage(e), "\n")
cat("ERROR :", conditionMessage(e),"---",i,"---",gsub("\\:","-",Sys.time()),file = "error.txt", append = TRUE, "\n")
#cat(message('** ERR at ', Sys.time(), " **"),file = "test_1.txt", append = TRUE)
#print(e)
},
warning = function(w){
cat("Warning :", conditionMessage(w),"---",i,"---",gsub("\\:","-",Sys.time()),file = "warning.txt", append = TRUE, "\n")
# print(w)
})
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## ERROR : Urgh, the iphone is in the blender----2 !
## [1] 7
## ERROR : Urgh, the iphone is in the blender !
## [1] 8
## [1] 9
## [1] 10