Can someone kindly advice me what to do?
When a transaction fails, all the changes done to the state are reverted and the ethers if supplied are sent back to the sender (but the gas supplied is not consumed).
Now if your transaction has failed and balance is not updated. This may be possible that your exchange has some technical glitch. They may not have handles cases of the failed transaction.
If the exchange has given you the private keys (which generally they don't), you can withdraw your balance from any other platform like MEW.
Else you could check the balance your account holds currently ahs shoot an email to the exchange support with all the details and wait for their response.
How can I prevent such happening in the future?
You should probably estimate gas before sending a transaction. That's easy if you are a programmer. You need web3.js for this. I am adding a code snippet for estimating gas for a contract function.
var contractAbi = eth.contract(AbiOfContract);
var myContract = contractAbi.at(contractAddress);
// suppose you want to call a function named myFunction of myContract
var getData = myContract.myFunction.getData(function parameters);
var estimatedGas = web3.eth.estimateGas({to:Contractaddress, from:Accountaddress, data: getData});
Note: You could supply gas a bit higher than that estimated by estimateGas
method because the excess amount of gas is refunded.
You can have a look at this stack question for refrence.