The idea is to catch an error and then handle the information caught by the handler. But it propagate it anyway and I don't know how to stop it.
Say, I have a component and I just want to have more information about error. For some reason, if I use try-catch, the error object doesn't show the line number - unlike the window.onerror. But when I use onerror handler, it bubbles the exception and it's caught higher what is not the desired behaviour.
Do you mean the error-boundaries of React?
Have you tried this?
Related
So basically I'm looking for a way to stop my bot from crashing because of user error or a bug in my code. What I want to bot to do is catch an error and respond to the message sender saying "Error! ${errormessage}". hopefully you understand what I mean.
You could use try-catch or simply .catch
This is a basic javascript topic, you can read and learn error handling here
Point to note is, you need to locate the line which is throwing the error by analyzing the error log.
Keep in mind you can only prevent the bot from crashing by using the above stated methods on runtime errors otherwise known as exceptions (ex: unhandledPromiseRejection, thrown during runtime), you cannot use this method on errors like TypeError, SyntaxError etc (Errors thrown while parsing the code), such errors can only be fixed by manually identifying the line and applying appropriate fix
Let's say component invoked an action and store tries to perform some operation but it couldn't, so store is trying to report the error back to view so user can be aware.
I can think of two options to handle this.
Have store emit an error event and then view components can listen to this event like they listen to change events and show the error to the user.
Store can add the error to the state object and fire a change event, then the the view components can check the error on the state objects and display error message accordingly.
Or is there any elegant way of handling this ?
Store normal and error informations in the store state is a better way to do that. In your scenario, you may need to show a error dialog or something else in order to tell user something is broken. That is, you have to rerender your components according to different states, so just put the error information in your store state and emit a change event.
Put everything which makes components change in the store state. That allows everyone to know your data flow easily and quickly.
I am writing a custom handler and wanted to see how stable it is and just let my browser request the same URL over and over. It doesn't crash but I get some messages like the one in the title.
I.e.
conn 0x7f7d6c001610 error: i=-2 errno=11 state=4 rc=3 br=721
This also happens when I execute the "hello" example but far less often.
Could you give me any pointers as to why this happens? Do I have to fix this?
This error report is not critical. This means connection to client dropped for some reason before request has been fulfilled.
This is my use case: I call fetch on a collection and receive a JSON from my server yet I have an error flag. This will always trigger the success flow, and I can detect the error by 2 means:
In my parse method - which is ugly.
By not using the success option, and using the Deferred's Done callback to check for the error. This is ugly as well since I have to call parse myself afterwards.
This would be solveable if Backbone had a validate function on collection but it doesn't...
Any suggestions?
EDIT: I know there's a way to do it by supplying my own Sync method but I got a bit lost there...
good question.. I'm not sure it's so bad to work with the parse method. It's name doesn't fit but it's all you've got in the natural path of the code and I guess you can just return an empty list without breaking anything.
The question to me is what is the cause of the error? If it's, say, a permissions thing (or some other error covered by the http protocol), you could return an error code from the server which should trigger your error callback..
I would like to somehow apply a try catch statement to all Actions as a backstop for any uncaught exceptions.
I think this would be particularly helpful for Ajax Actions, because the catch statement could send back a default 4xx status code. Prototype's onFailure() function could then do the client-side error handling.
How can I do this without wrapping the Action call with a try/catch in the cake dispatcher like this:
try {
output = $controller->dispatchMethod($params['action'], $params['pass']);
}
catch {...}
Does anybody have a suggestion or another workable strategy for gaining this functionality without touching the dispatcher?
How do people feel about putting exception handling in the Displatcher? I imagine when cake drops php 4 support, there will be a built-in mechanism for this.
[Edit] I've looked into the cake Error Handling. Without try/catch it seems like there is a big loss in functionality. And, I am hesitant to mix cakeErrors and other Exceptions.
In app/webroot/index.php replace the line
$Dispatcher->dispatch($url);
with
try {
$Dispatcher->dispatch($url);
} catch(Exception $e) {
// do exception handling
}
I'm not too sure why you would want to do this. You can check the params to see if it's an ajax call in the controller using,
if($this->params['requested'])
I don't know what kinds of exceptions your application might create, but if it's a missing action, view or similar, Cake will output an error page, which you can customise in the app/views/errors folder.
The book has some information on how to handle errors using CakePHP's built in error handler here, http://book.cakephp.org/2.0/en/development/errors.html
You could also have a Google around for articles and tutorials on creating your own custom error handler, or extending the built in one, so that it wraps all dispatch calls in a try{}catch{} from the core of the dispatch cycle.