C (gcc), 71 65 bytes
f(char*p){p=*p-'h'?*p&&puts("err"):f(p+1)||!puts("Hello World");}
- Thanks to @rtpax for saving 6!
f(char*p){p=
- function tacking a program
and returning with the eax trick, reusing p
.
Calls itself recursively.
Recursion happens before program
execution so if all steps are correct a false
value is returned and the program
is executed.
If there's an error a truthy
value is returned and program
is not executed at all, an error message is displayed.
*p-'h'? `...` :f(p+1)||!puts("Hello World"); - check each character in program : if h continue recursion and if result is false program do its job. p is true if there was an error, false instead. - if not h stop recursion and : *p - if end of program p is false &&puts("err") - if not end of program display error p is true.
61 58 bytes alternative less interesting solution which runs the program and stops when an error happens
f(char*p){*p&&puts(*p-'h'?"err":"Hello World")>4&&f(p+1);}
- Saved 3 thanks to @rtpax !