How to create function for catching any warning alert box?

How to check any pop up? can you explain this.