In no conceivable world am I a lawyer, but to what degree can ignorance be used as a valid excuse for breaking any law?
Usual caveats that this is a general overview apply here - there are always going to be exceptions and nuances, and so this is not legal advice.
Most criminal laws requires
mens rea to be established - that is, a guilty mind. (Some few criminal laws are what one would call "strict liability" where just physically doing the thing (the
actus reus), regardless, is enough.)
Mens rea is usually broken down into: 1) Deliberate/Premeditated/Intended, 2) Knowledge, 3) Recklessness (willful blindness), 4) Negligence. My purpose in framing it this way is to convey that different crimes may have specific mental states that have to be proven. I think most people would be most familiar with this concept via murder trials. Was the killing (the physical thing) intended, or accidental? And so was it murder or manslaughter?
(There's a whole convoluted digression to be had here re: transferred intent, and the various mental states and standards each jurisdiction might have for the same crime. There are general patterns, but it's very jurisdiction specific. But for our purposes, we just have to know the required mental state depends on the crime itself - often that is written right into the statue.)
So that's what it is.
Proving mens rea is just as varied, and is often accomplished solely by circumstantial evidence, given the 5th amendment privilege against self-incrimination. Otherwise, we'd only get murder convictions when there was a confession by the killer that they had the required mental state at the time the killing happened.
And that bring us to your question.
First off, the prosecution has to prove the case beyond a reasonable doubt. So, at the end of the submission of evidence to the jury, if that evidence supports another equally non-criminal possibility, the jury should be acquitting.
There are somewhat rare "mistake of fact" defenses, where the accused believed "something else" was going on. As a practical matter, that usually requires a defendant to testify and be subject to cross examination.
There are
very rare "mistake of law" defenses.
There are
very rare "out of my gourd" defenses, which are not so much a mistake of law or fact but a complete obliviousness to reality that precludes forming any intent at all. (Insanity defenses do not work nearly as well TV portrays - they are often just a pause button.)
But generally, circumstantial evidence will work - what did the defendant say or do? What's a reasonable interpretation of the facts. Juries get that.