使用mod_cgi&的mod_perl [英] Catching errors with both mod_cgi & mod_perl
问题描述
感谢大家提前。
我一直在做错误处理的研究,我不觉得我对我应该做。
I've been doing some research on error handling and I don't feel like I'm getting a solid understanding of what I should do.
序言:我的代码生活在Apache中,在浏览器中执行,我的目标不包括命令行执行。
Preamble: My code is living in Apache and executed in the browser, my goals don't include command line execution.
我想拥有CGI :: Carp(fatalsToBrowser)的行为,能够捕获输出,并能够将其放在我自己的模板页面中,通过电子邮件发送给我...我没有注意到fatalsToBrowser不适用于mod_perl。有人知道为什么吗Apache / mod_perl如何处理?
I'd like to have the behavior of CGI::Carp (fatalsToBrowser) with the ability to capture the output and be able to throw it in my own templated page, email it etc... I did notice that fatalsToBrowser doesn't work with mod_perl. Does anyone know why? How is Apache/mod_perl getting in the way?
第一个目标:我想把一些东西放在一起,如果代码正在使用mod_perl或mod_cgi执行。
First Goal: I'd like to put something together that works if the code is being executed with mod_perl or mod_cgi.
第二个目标:我想要一个捕获所有类似错误的高级方法。 NET的Application_Error(在global.asax中)和PHP的set_exception_handler()和set_error_handler()方法。这些允许您在出现错误时进行控制,而不会在乱码 / gross try-catch语句中包装代码。
Second Goal: I'd like to have a high-level method(s) that catches all the errors similar to .NET's Application_Error (in global.asax) and PHP's set_exception_handler() and set_error_handler() methods. These allow you to take control when an error is raised, without wrapping code in messy/gross try-catch statements.
我已阅读/评论的内容:
Things I've read/reviewed:
1。) Perl中的OO异常处理,但不是我在寻找。我想要捕获的大多数东西都是die()ing。下一个链接也表示这篇文章已经过时了,不推荐使用。
1.) OO Exception Handling in Perl, but wasn't what I was looking for. Most of the stuff I want to catch is die()ing. The next link also says that this article is out of date and deprecated.
2。) Perl:$ SIG {__ DIE__},eval {}和堆栈跟踪,但是我没有从这个与我的目标相关的很多。
2.) Perl: $SIG{__DIE__}, eval { } and stack trace, but I didn't get much from this related to my goals.
3。)实用模式Perl(O'Reilly),第21章错误处理和调试。感谢所有我的perl代码使用严格和警告启用,第6章注意mod_perl编码中提到的最重要的事情已经完成。
3.) Practical Mode Perl (O'Reilly), Chapter 21 "Error Handling and Debugging". Thankfully all my perl code uses strict and warnings are enabled, and most important things mentioned in Chapter 6 "Coding with mod_perl in Mind" are already done.
4)我的通过学习Perl,Perl Cookbook,Perl编程和高阶Perl中的内容表,并没有看到任何突出的东西。如果你觉得我错过了那里,请让我知道。 :)
4.) I've dug through the tables of contents in "Learning Perl", "Perl Cookbook", "Programming Perl" and "Higher Order Perl" and didn't see anything that stuck out at me. If you think I missed something there please let me know. :)
我不记得在哪里(也许在实用mod_perl,但我已经读过你应该不要混淆$ SIG {__ DIE __}。
I don't remember where (maybe in "Practical mod_perl", but I've read that you should not mess with $SIG{__DIE__}.
推荐答案
您是否阅读了 mod_perl
网站在替代异常处理技巧上的一些内容?关于如何使用覆盖全局 die()
函数而不是使用 $ SIG {__ DIE __}
。一种更清洁的方法,但不完美。
Have you read the mod_perl
website's bit on Alternative Exception Handling Techniques? It discusses about how you can catch uncaught exceptions though the use of overriding the global die()
function instead of using $SIG{__DIE__}
. A much cleaner method but not perfect.
这篇关于使用mod_cgi&的mod_perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!