capturing exceptions and local details with a decorator /u/OhGodSoManyQuestions Python Education

I want an easy way to capture exceptions (and local data) in large codebases by simply adding a decorator to functions and/or classes. The use case looks like:

@capture_exceptions class MyClass: def __init__(self): .... 

In the event of an exception, I want to capture the script’s path, the class name, the method name, the arguments, and the details of the exception.

I have code that does this now using inspect.stack, traceback, and some native properties. But it’s brittle and it feels like I must be doing this the hard way.

Without using 3rd-party tools, is there a direct way to get this local data from within a decorator?

submitted by /u/OhGodSoManyQuestions
[link] [comments]

​r/learnpython I want an easy way to capture exceptions (and local data) in large codebases by simply adding a decorator to functions and/or classes. The use case looks like: @capture_exceptions class MyClass: def __init__(self): …. In the event of an exception, I want to capture the script’s path, the class name, the method name, the arguments, and the details of the exception. I have code that does this now using inspect.stack, traceback, and some native properties. But it’s brittle and it feels like I must be doing this the hard way. Without using 3rd-party tools, is there a direct way to get this local data from within a decorator? submitted by /u/OhGodSoManyQuestions [link] [comments] 

I want an easy way to capture exceptions (and local data) in large codebases by simply adding a decorator to functions and/or classes. The use case looks like:

@capture_exceptions class MyClass: def __init__(self): .... 

In the event of an exception, I want to capture the script’s path, the class name, the method name, the arguments, and the details of the exception.

I have code that does this now using inspect.stack, traceback, and some native properties. But it’s brittle and it feels like I must be doing this the hard way.

Without using 3rd-party tools, is there a direct way to get this local data from within a decorator?

submitted by /u/OhGodSoManyQuestions
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *