def METHOD_NAME(self):
    cu = torch.jit.CompilationUnit('''
        def foo(cond):
            if bool(cond):
                raise ValueError(3)
            return 1
    ''')
    cu.foo(torch.tensor(0))
    with self.assertRaisesRegex(torch.jit.Error, "3"):
        cu.foo(torch.tensor(1))
    def foo(cond):
        a = 3
        if bool(cond):
            raise ArbitraryError(a, "hi")
            if 1 == 2:
                raise ArbitraryError
        return a
    with self.assertRaisesRegex(RuntimeError, "undefined value ArbitraryError"):
        torch.jit.script(foo)
    def exception_as_value():
        a = Exception()
        print(a)
    with self.assertRaisesRegex(RuntimeError, "cannot be used as a value"):
        torch.jit.script(exception_as_value)
    @torch.jit.script
    def foo_no_decl_always_throws():
        raise RuntimeError("Hi")
    # function that has no declared type but always throws set to None
    output_type = next(foo_no_decl_always_throws.graph.outputs()).type()
    self.assertTrue(str(output_type) == "NoneType")
    @torch.jit.script
    def foo_decl_always_throws():
        # type: () -> Tensor
        raise Exception("Hi")
    output_type = next(foo_decl_always_throws.graph.outputs()).type()
    self.assertTrue(str(output_type) == "Tensor")
    def foo():
        raise 3 + 4
    with self.assertRaisesRegex(RuntimeError, "must derive from BaseException"):
        torch.jit.script(foo)
    # a escapes scope
    @torch.jit.script
    def foo():
        if 1 == 1:
            a = 1
        else:
            if 1 == 1:
                raise Exception("Hi")
            else:
                raise Exception("Hi")
        return a
    self.assertEqual(foo(), 1)
    @torch.jit.script
    def tuple_fn():
        raise RuntimeError("hello", "goodbye")
    with self.assertRaisesRegex(torch.jit.Error, "hello, goodbye"):
        tuple_fn()
    @torch.jit.script
    def no_message():
        raise RuntimeError
    with self.assertRaisesRegex(torch.jit.Error, "RuntimeError"):
        no_message()