Anyway, to solve your first problem, add the definition f[_]:= Throw["Your error message here"}
To solve your second problem, use Block instead of Module (though in your simple example given here the solution is to just use neither).
I've dreamed about creating a language like this, but had to give up because it makes diagnostics impossible in case o typos and things like that..
My best bet now is to have some quote syntax to make a symbol stand for an abstract symbol, like
1 + x -- this sums 1 with x, and errors if x is unbound
1 + 'x -- this is an abstract expression, doesn't care if x is bound or not
Like lisp, except with some first class support to things like derive(1 + 'x, 'x), and, well, every operator needs to respect quoted symbols.. even if + were a user-defined operator or function, 1 + 'x needs to return (the AST) 1 + 'x. I suppose this is the same as Mathematica, except that Mathematica doesn't need quoting
I claim any semantics which resulted in `11` would be extremely confusing, because it would imply the following also resulting in `11`, which is obvious nonsense:
y = 10;
Module[{y}, 1+y]> y = 10; > Module[{y}, 1+y]
Yes that is precisely the point: because of Mathematicas weird evaluation model, you cannot have ordinary lexical scope as in every other programming language, but the only sensible thing to do is to rename variables under the hood. It is then very easy to leak those renamed variables accidentally in the global scope where you cannot do anything useful with them, because the symbols `y` in the global scope and in the subscope are different.
Another point that the example was meant to illustrate is that once you assign some value to a variable, you can no longer do symbolic manipulation with it (note that in the example, we have replaced 1 by 10 in the end).
y = 1;
expression = Block[{y},1+y];
Print[expression]
2
There are also the 'formal' symbols, e.g. https://reference.wolfram.com/language/ref/character/FormalY... if you want a symbol that will never be assigned a value but can still be substituted using ReplaceAll etc.
That issue alone has caused me so many errors simply from mistyping some function or variable name. For simple expressions, such bugs are pretty obvious to spot but if the same occurs deep inside a chain of function calls, this often lead to completely wrong results because the bug got masked by some other manipulations I did on the result of the function call.
Of course, there are tons of hacks and ad-hoc workarounds in Mathematica to get around this (imho fundamentally broken) behaviour to the tune of "just stick another `Evaluate` here" or "just change the function definition from `g[x_]` to `g[x_?NumericQ]` to call the function only when the argument is numeric and otherwise leave it unevaluated".
The situation with the scoping rules is not much better. Consider for instance the following code:
Can you guess what happens if I print out `expression` now? Yes, Mathematica has just renamed our variable. If now we wanted to set `y` in our expression to some concrete value, of course the obvious thing to try doesn't work, but just gives me some bullshit: These are all only some simple examples of why doing any kind of metaprogramming in Mathematica just sucks.