The defence of necessity is available to a person who committed a criminal offence, but only did so to avoid certain consequences where they would have been in immediate irreparable harm, or in order to protect someone else who they were bound to protect. The way a person reacts, needs to be proportionate to the level of harm, or peril they are facing (R v Loughnan  VR 443 (CCA)).
Whether or not this defence is made out, depends on the facts.
Essentially, you need to weigh up the act committed by the person, against the harm they would have experienced had they not acted in that manner. The next question to be asked is whether the act was proportionate?
Who has to prove what?
Where a person is raising the defence of necessity, the onus is on them to call evidence to prove that they were acting out of necessity. If the accused is able to successfully do so, then the prosecution must negative the defence, beyond reasonable doubt.
What the cases say
In R V Roger (1966) 86 A Crim R 542, it was said that this defence exists for cases where someone has been so overwhelmed by a certain situation, that they have felt forced to break the law. However, there cannot be the situation, where people can simply decide not to obey the law, and apply their own set of values to situations when they arise.
For this reason, the defence of necessity is very difficult to make out successfully and requires a great deal of work and proper preparation.