One of the risks of an anaesthetic is that stomach contents can be regurgitated or that there may be vomiting, and you lungs will be contaminated with stomach contents. This can have very serious consequences. For this reason your anaesthetist will instruct you not to take any fluid for at least two hours or solid food for four to six hours before your operation.
If your operation is been carried out as an emergency and there is not time to allow your stomach to empty, your anaesthetist has to use special techniques to minimise the risk of aspiration, as it is called. But it is always best to keep risks to an absolute minimum, and pre-operative starvation is the best way to do this.