Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1 | package testutil |
2 | |||||
3 | // CallAndRecover calls the function f and returns the result of recover(). | ||||
4 | // This minimizes the scope of the deferred recover, to ensure f is actually the | ||||
5 | // function that paniced. | ||||
6 | func CallAndRecover(f func()) (result interface{}) { | ||||
7 | defer func() { | ||||
8 | result = recover() | ||||
9 | }() | ||||
10 | f() | ||||
11 | return | ||||
12 | } |