From 8805e79189939d61149b094071517aa7b78048a5 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Sun, 19 Feb 2012 01:21:07 +0100 Subject: [PATCH] Properly handle Gob panic --- cache.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cache.go b/cache.go index f99f1e5..4fa92a5 100644 --- a/cache.go +++ b/cache.go @@ -199,10 +199,9 @@ func (c *cache) DeleteExpired() { } // Writes the cache's items (using Gob) to an io.Writer. -func (c *cache) Save(w io.Writer) error { +func (c *cache) Save(w io.Writer) (err error) { enc := gob.NewEncoder(w) - var err error defer func() { if x := recover(); x != nil { fmt.Printf(`The Gob library paniced while registering the cache's item types! @@ -219,7 +218,7 @@ were stored in cache, at https://github.com/pmylund/go-cache/issues/new gob.Register(v.Object) } err = enc.Encode(&c.Items) - return err + return } // Saves the cache's items to the given filename, creating the file if it