I know we can detect that the transaction is going to be failed with the "Out of gas" warning beforehand but is it possible to find the exact error before sending it to the blockchain. How can we simulate a transaction as its mined (failed) and find the exact error (or line of code) where it failed?
So if I understand correctly you want to detect this kind of errors in advance, without actually sending the transaction to the real blockchain.
Whether the transaction succeeds or not may possibly depend on the contract state. Therefore it's not enough simply to take the same contract offline and test that even if that might get you quite far. So what you can do it take the entire blockchain with its state, run it locally offline and execute transactions against it. Then you can roll back transactions (continue mining from a certain block) as you wish.
Technically I'm not exactly sure how this should be accomplised even if I know it can be done. Basically if you have a full synchronized node you have all the data you need - you just need to change it to run locally in your node instead of connecting to other peers.