Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // 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 Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 5 | package 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. |
| 10 | func CallAndRecover(f func()) (result interface{}) { |
| 11 | defer func() { |
| 12 | result = recover() |
| 13 | }() |
| 14 | f() |
| 15 | return |
| 16 | } |