

def test_error(msg):
    import sys
    sys.stderr.write('Error: %s\n' % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except:
        pass

    if not got_exception:
        test_error('Did not get exception when %s' % action)



def test_error(msg):
    import sys
    sys.stderr.write('Error: %s\n' % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except BaseException as e:
        test_error('Got unexpected exception: %s' % str(e))

        got_exception = True
    except:
        test_error('Got non-standard exception')

        got_exception = True

    if not got_exception:
        test_error('Did not get exception when %s' % action)

Update Python expect_exception to be like C++'s
Update Python expect_exception to be like C++'s

  
  
  def test_error(msg):
      import sys
      sys.stderr.write('Error: %s\n' % msg)
  
  
  def expect_exception(action, kind, func, *args):
      got_exception = False
  
      try:
          func(*args)
      except kind:
          got_exception = True
+     except BaseException as e:
+         test_error('Got unexpected exception: %s' % str(e))
+ 
+         got_exception = True
      except:
-         pass
+         test_error('Got non-standard exception')
+ 
+         got_exception = True
  
      if not got_exception:
          test_error('Did not get exception when %s' % action)
  
Update Python expect_exception to be like C++'s
## Code Before:


def test_error(msg):
    import sys
    sys.stderr.write('Error: %s\n' % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except:
        pass

    if not got_exception:
        test_error('Did not get exception when %s' % action)

## Instruction:
Update Python expect_exception to be like C++'s
## Code After:


def test_error(msg):
    import sys
    sys.stderr.write('Error: %s\n' % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except BaseException as e:
        test_error('Got unexpected exception: %s' % str(e))

        got_exception = True
    except:
        test_error('Got non-standard exception')

        got_exception = True

    if not got_exception:
        test_error('Did not get exception when %s' % action)
