I am grateful to @Drew for also providing me with similar code for Emacs Dired. With it, clicking on a large file in Dired will result in a message about the file being too big to open.
(defun my-dired-find-file ()
"Like `dired-find-file', but raise error file is too big."
(let ((find-file-run-dired t)
It sounds like you want this only for interactive use, i.e., a command.
Define your own substitute for command find-file (or find-file-other-window etc.).
Have you command check the file size, using functions file-attributes and file-attribute-size, and refuse to open the file if it is bigger than some threshold you set.
For example (untested):