[DependencyInjection] Added exception to avoid fatal during compile in a frozen dumped container

| Q | A |
| Bug fix? | yes |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #10428 |
| License | MIT |
| Doc PR | N/A |

@fabpot  / @stof : Should I remove the fonctionnal tests as it is implicit in the unitary ones ?