You should've known better than

Hello,

I couldn’t find an explanation for this expression with Google.
From what I’ve seen, it is followed by something undesirable, a negative outcome, and the meaning is “you shouldn’t have done that”.
And still, from a paper dictionary I’ve learned that it means something like “you should’ve known that it would be better to (do something)”, so it would be followed by a desirable outcome.
Could someone please explain how can I use it correctly?

Thanks in advance.

Search for assumption and deduction. This is a deduction sentence with meaning: It’s a pity that you didn’t know it better.

Thanks for the answer, Vietanhpham_Winter, but unfortunately I don’t follow you.

I don’t think this is the meaning of this expression.
Could you please elaborate further? Anyone else?

You should’ve known it better. It means I wanted you to know it better but in fact, you didn’t. One more example, You should’ve gone to the party means it was advisable that you go to the party(should implies that the party is very good for you) but because of an indefensible reason, you couldn’t go to the party.

“You should’ve known better than”

Example: You should’ve known better than to invest with Madoff.

The returns were to good to be true, yet you invested your money anyway because you were greedy.

It’s making a moral judgement on the past actions of the other person.

Thank you kindly.