blob: 34230e9fc7f94aea0186cf17144a1440836c2969 [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Jiri Simsa5293dcb2014-05-10 09:56:38 -07005package testutil
6
7// CallAndRecover calls the function f and returns the result of recover().
8// This minimizes the scope of the deferred recover, to ensure f is actually the
9// function that paniced.
10func CallAndRecover(f func()) (result interface{}) {
11 defer func() {
12 result = recover()
13 }()
14 f()
15 return
16}