code: def test_exception_safe(self):
      s = self.cls()
      o1 = object()
      o2 = object()
      with s(o1):
          with self.assertRaisesRegex(ValueError, "expected"):
              with s(o2):
                  raise ValueError("expected")
          self.assertIs(s.peek(), o1)
      self.assertEmpty(s)
  
imports: import collections
  import copy
  import pickle
  import threading
  from absl.testing import absltest
  from absl.testing import parameterized
  import cloudpickle
  import dill
  from haiku._src import data_structures
  import jax
  import tree
label_desc: Use image node_id 8 for calling the StackTest obj's underlying member method code with example usage: obj.test_exception_safe() without return types