The sentence is: I was very surprised ________That she didnīt pass the exam.
Can I use to or by hearing?
You actually use "to hear"
Subject + linking verb + adjective + infinitive + "that-clause" is a common structure:
He seemed pleased to find out that she wasn't coming
I was sad to learn that my dog died
They looked shocked to discover that their son hadn't done his homework
Hope that helps!