is there any way to get custom messages to web client?

for example i want send a message when user is not authenticated... if there is some error occured in updating... etc...

is there any way to catch such exceptions in the side of web client?