I have a question about kohana exceptions.
I have a site that I want to put in production, and I don't want the exceptions to be simply thrown (like they are now), but I want to redirect the user to another page in case of an exception occured.
I use kohana 3, and I wonder: how can I catch an exception and redirect the user to another page if an exception happens:
example of code:
instead of
if ( ! $sale->loaded())
{
throw new Kohana_Request_Exception('Sale not found.');
}
I want: something like: page not found.
thank you!
What you'll need to do is register your own exception handler.
Take a look at the Error Handling documentation for an idea on what to do. Basically, you can capture any type of exception you want and do something specific with it (such as display a 404 page).
Related
I would like to have many devices testing a game, and I find the best way to debug a game and solve specific code problems is to have the device connected and in debug mode in Adobe ANIMATE, that way I can catch any Errors in the Output window.
For Example, if I am debugging and connected to Animate, the output window will throw errors like :
ReferenceError: Error #1065: Variable bg_storage is not defined.
at global/flash.utils::getDefinitionByName()
at Game/stageAdd()[/Users/**/Game.as:360]
Now I know exactly what the problem is and where to find it. I love errors like this.
My question :
If I didn't have a device connected to Animate in Debugging mode, is there a way to make the game detect any errors thrown and store them as a String, that way I can put up a big text block on the game of the error string and keep track.
or at least a way to log them some how?
Ex :
If an error is thrown, have that error text set as a String variable, then have a text box write out that String variable.
I hope that isn't too confusing. If I am going about debugging in a poor way, I would love to know what you guys do to keep track of errors without being connected to debug mode.
EDIT
I can see an approach is you to add an uncaughtErrorEvent event to each function to be able to catch these errors...
loadbar.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR ... )
I am trying to make it so any error thrown in any part of the game will trace that error somewhere to a String value that I can call, so that I can see any error thrown during a play test session without being connected to debug mode.
Thanks!
Sure. There's a class intended exactly for that: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvent.html See examples at the bottom of the page to listen to the right instances for that event.
You are also free go grab my own class that does the thing you want: https://bitbucket.org/thydmitry/ru.delimiter/src/2756fadd741a6d44276fde1701470daf24cebfa8/classes/ru/delimiter/utils/Log.as?at=default&fileviewer=file-view-default
You will need to add it to your project and then call in the main document class (in constructor, preferably):
Log.create(this);
Log.handleExceptions(this, true);
I have angular2 project, how can I catch errors on client side, error 'Failed to load'. I want to control situation if some of html files doesn't exists my page wouldn't fail, but I'll get exception in console.
Thank you.
As per my understanding, you want to handle exception, so you can done it in typescript using try catch and finally block. typescript allow us to use try catch.
A reference for Try Catch
https://www.c-sharpcorner.com/UploadFile/5089e0/try-catch-statement-in-typescript/
If you need in html, then you need to handle as case in html using some variables
I'm working on some flash app. Now, to test customer side of it I can use Flash Player debugger version that will save logs and show error messages. When it's deployed on the customer side - they will have a regular Flash Player version which means I will have no access to error messages if errors will happen. So I would like to equip it with some tool that would capture all of my trace messages in code and errors text. As for trace messages that's fairly simple, I just override the function in my code so it sends a POST request with trace message to a logger server, but how can I get a hold of the error message? Is there a known approach to this or some trick that somebody can suggest?
You can install the debug version of flash as your browser's default (in Chrome, you must disable the built-in player), so if you wanted to test user experience and debug, this would be the ideal solution.
However, to answer your question: there's no method for universally catching all errors, and redirecting them (that I know of). You'd have to encapsulate problem code ahead of time with try...catch statements, and send the property back on catch. For example:
try {
this["foo"]();
} catch (e:Error) {
trace(e);
}
In the debug version, the traced value would be TypeError: Error #1006: value is not a function. And while the standard version will only output TypeError: Error #1006, (a notably less descriptive error), what we're missing is any reference to where the error occured. To get this, we need to use Error.getStackTrace() to see the call stack and the line where the error occurred. In debug, this outputs the following:
TypeError: Error #1006: value is not a function.
at Shell_fla::MainTimeline/init()[C:\Projects\shell.as:91
In the standard client, we get a dissapointing null. In short, you cannot get any valuable info from the client versions.
The best advice I can give is to write around your problem code with your own custom error reports. For example, catch IO errors and trace the file it failed to load, or if you're expecting an object.foo, first try if (object.hasOwnProperty("foo")) { // do something } else { trace("foo not found in " + object.name) }. Code defensively.
Cheers,
I've discovered this post on StackOverflow:
How to catch all exceptions in Flex?
It answers my question, strange that I haven't ran into it while I was googling prior to asking.
I'm making from client different ajax calls to web methods in my page. Some of the methods will throw in some cases exceptions. I want to be able to show the message of the exception to the user.
I have found that I can use "<customerrors mode= Off>" but also this approach How to return custom exception message to Ajax call?
The second one seems like a lot of extra coding in JS, but I don't know if the first is acceptable in a production environment.
Could you please advice me on this!
Thank you.
EDIT: Example: I'm adding a new user and validation in my DB says it is already there, I want to be able to show the message in a div/span/label (in a jquery dialog) but in the same page and without page postback.
Create One Error.aspx page and write the following code in global.asax code file.
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
string ErrorMessage = Server.GetLastError().ToString();
Session[ErrorMessage] = ErrorMessage;
Server.ClearError();
Response.Redirect("~/Error.aspx");
}
Write Session[ErrorMessage] on your Error.aspx page.
You will get exception message whenever exception occur in web application and it will show on Error.aspx page.
My ejb3 application running on JBOSS6 already has a customized Exception handler "Ejbexception.java" which extends Exception class
I want to use the same to trap Exceptions with some number and send back the same to the Client Code for handling gentel message .
ex:
try{
.....
}catch(SQLException ex){
throw new EjbException("1001");
}
Now HOWto get the "1001" on the Client Code ?????
thx in advance
karthik
Did you write this Ejbexception class yourself? If so, that's a poor choice of name, because there's already a javax.ejb.EJBException in the library. However, it will work: when you throw it, the container will transport it to the client, who can then catch it. The string you inserted will be available from the exception's getMessage() method, just like normal.
If you're actually throwing a javax.ejb.EJBException here, then things are slightly different. That exception is aimed at the container, not the client. I actually don't know how it's made visible to the client. My suggestion would be to switch to using a custom exception, which the container will then pass to the client.