I like your questions, and they've long been something I've thought about. But sadly, the answer has always been "Yes." In fiction, Victor Hugo asked the same question, as Jean Valjean was sentenced to penal servitude for stealing a single loaf of bread to feed a starving child. The "law," as represented by Inspector Javert, could allow no such excuse.
I've asked the same question myself. What if, during hurricane Katrina in New Orleans, a man with a diabetic child broke into a closed drug store to get only as much insulin as his diabetic daughter required to survive? Would he still be committing a crime? I think the answer is probably yes. Could the courts make an exception and excuse him? I don't know, but I'd like to see it tested.
Welcome to trying to be human. Welcome to philosophy.