How can I replace all 'die's with 'confess' in a Perl application?

后端 未结 4 1309
迷失自我
迷失自我 2021-02-02 13:56

I\'m working in a large Perl application and would like to get stack traces every time \'die\' is called. I\'m aware of the Carp module, but I would prefer not to search/replace

4条回答
  •  野的像风
    2021-02-02 14:49

    The Error module will convert all dies to Error::Simple objects, which contain a full stacktrace (the constructor parses the "at file... line.." text and creates a stack trace). You can use an arbitrary object (generally subclassed from Error::Simple) to handle errors with the $Error::ObjectifyCallback preference.

    This is especially handy if you commonly throw around exceptions of other types to signal other events, as then you just add a handler for Error::Simple (or whatever other class you are using for errors) and have it dump its stacktrace or perform specialized logging depending on the type of error.

提交回复
热议问题