You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/datatable-programming.Rmd
+44Lines changed: 44 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -456,6 +456,50 @@ DT[, eval(cl)]
456
456
DT[, cl, env = list(cl = cl)]
457
457
```
458
458
459
+
## Error handling with classed conditions
460
+
461
+
Starting from version 1.17.0, `data.table` provides specific error classes for common operations, making it easier to handle errors programmatically. This is particularly useful when writing robust code or packages that use `data.table`.
462
+
463
+
### Available error classes
464
+
465
+
`data.table` now provides four specific error classes:
466
+
467
+
-`dt_missing_column_error`: When referencing columns that don't exist
468
+
-`dt_invalid_input_error`: When providing invalid input types or empty required arguments
469
+
-`dt_unsortable_type_error`: When trying to sort/key unsupported types
470
+
-`dt_join_type_mismatch_error`: When column types are incompatible in joins/set operations
DT1 <- data.table(id = 1:3, value = c("a", "b", "c"))
488
+
DT2 <- data.table(id = 1:3, value = 1:3)
489
+
490
+
tryCatch({
491
+
fintersect(DT1, DT2)
492
+
}, dt_join_type_mismatch_error = function(e) {
493
+
cat("Type mismatch in join:", conditionMessage(e), "\n")
494
+
}, error = function(e) {
495
+
cat("Other error:", conditionMessage(e), "\n")
496
+
})
497
+
```
498
+
499
+
### Backward compatibility
500
+
501
+
All error classes inherit from base R's condition system, so existing `tryCatch(..., error = ...)` code continues to work unchanged. The new classes simply provide more specific handling options when needed.
0 commit comments