未处理的异常方法 [英] Unhandled Exception method

查看:92
本文介绍了未处理的异常方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写了一个继承Exception类的错误处理程序类后,我正在努力处理未处理的异常。


错误处理程序类中的未处理异常静态方法似乎很好在构造中使用set_exception_handler()的想法,但这意味着我不能合法地调用类方法。


有人可以建议一个更好的主意吗?

Having written a error handler class that inherits the Exception class, I am struggling what to do with unhandled exceptions.

An unhandled exception static method within the error handler class seemed a good idea with set_exception_handler() in the construct, but this means I cannot call legally that classes methods.

Can someone suggest a better idea?

展开 < span class =codeDivider> | 选择 | Wrap | Line数字

推荐答案

@code green


只是为了走上正轨,你想要与您的班级一起处理被捕获的异常?那么继承异常似乎是不对的(我的意思是,有什么好处?)


还有一点:

set_exception_handler()在你抛出异常时经常注册?


怎么样(虽然没有必要把它放到一个类中)
@code green
just to get on the right track, you want to process caught exceptions with your class? then it doesn''t seem right to inherit from Exception (I mean, what is the benefit?)

one more point:
set_exception_handler() is registered as often as you throw an exception?

what about (though there''s no need to put this into a class)
展开 | 选择 | Wrap | 行号



有什么好处
what is the benefit



对不起。我正在抛出一些想法并且可能提交了最糟糕的一些。


基本上我正在寻找一个放置未处理异常函数的地方。目前它位于所有脚本中包含的全局配置文件中。


我有另一个错误类(不是从Exception继承),它将所有错误收集到一个字符串/文件/数组中稍后处理,实例化一次。


如果我在其中放入未处理的异常,则显然必须是公共静态。

如何允许此方法访问类中的其他方法和成员。

I''m sorry. I was tossing a few ideas about and probably submitted the worst of them.

Basically I am looking for somewhere to put an unhandled exception function. At the moment it is in a global config file included in all scripts.

I have another error class (not inherited from Exception) that collects all the errors into a string/file/array for later handling, which is instantiated once.

If I put unhandled exception in this it obviously has to be public static.
How do I allow this method to access other methods and members in the class.

展开 | 选择 | Wrap | 行号


在我继续之前,你如何抛出异常?

@code green


静态?即该方法是类的一部分,而不是对象的一部分(您不能使用非静态成员)。
before I proceed, how do you throw the Exception?

@code green
staticly? i.e. the method is part of the class, not of the object (you can''t use non-static members).


这篇关于未处理的异常方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆