error-handling

PHP alternatives to handling malformed input instead of throwing errors

There are many functions (well most really) in the PHP language that get all upset and throw warnings and notices when they don't like something about their input - rather than just returning FALSE (though they do that too). One place this is really common is in the GD and string functions. They are very particular about their arguments...

JavaScript simple "error-handling" by replacing NaN with conditional

I was wondering how I can detect false input type and instead of presenting the user with NaN, have a logical piece of information be displayed. Here is my code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Quadratic Root Finder</title> <script> window.onload = function() { document.getE...

Rails Return Error on Class Method

I have a class method that I would like to return a error from, is something like this possible? class Foo < ActiveRecord::Base def self.do_this if b = Bar.find_by_id(5) return 'Yea' else self.errors.add_to_base('I was not found') end end end ...

Removing ModelErrors from ModelState once written to ValidationSummary()

I may be approaching this from the wrong angle entirely, but hopefully someone will know a way of acheiving what I'm after. I reference a web service, which returns an ErrorInfo object. I add each returned error to the ModelState as a ModelError: foreach(ErrorInfo error in serviceResponse) ModelState.AddModelError(error.AssociatedF...

Error handling in rails

Oddly I'm having a hard time finding good docs about basic error handling in rails. I'd appreciate any good links as well as thoughts on a handling errors in a really basic method like this: def self.get_record(id) People.first( :conditions => ["id = ?", id] ) end 1) I could verify that id != nil, and that it's numeric. 2) I ...

Throwing an Exception on every application error

I have an application based on Zend Framwork. In one Model I am calling a method from another Model. When I call this method I use try-cath block for handling of strange situations. Model1. try { $result = Module_Model2_Name->method(); } catch (Exception $e) { // Do Something } Catch should be work if we find a throw in try bl...

your challenges with using splunk

Hi all, In our application, we log critical information to log text files for later debugging purpose. With splunk its easy to identify a problem if I already have some data points like order number or "object reference not found" type of error. But its challending for me to get an overall picture of a problem using splunk. To be able t...

Handling Net::HTTP.get failures

The following line: page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com")) When passed a url that is properly formatted, but doesn't go anywhere (like the example above), dies out with: getaddrinfo: nodename nor servname provided, or not known I'm trying to figure out how to "begin / rescue" this condition, but I can't...

How to see the error and still keep the program on in the Python shell?

I know try/except can handle errors in my program. But, is there a way of making the error be displayed in the program execution, be ignored and let the execution go on? ...

Why am I seeing 2 error pages when doing a Server.Transfer from Application_Error and errorMode="Custom"?

My question is closely related to this question. Here is a quick synopsis: My app is running in Classic Mode. I have the following code in Global.asax protected void Application_Error(Object sender, EventArgs e) { // ... boring stuff... HttpContext.Current.Server.Transfer("~/MyErrorPage.aspx", true); } Eve...

How to make custom 404 page be a forward, not a redirect in Tomcat

I've got a Spring MVC app served in Tomcat. When the user enters a page that isn't found, it displays my default 404 page, as set in web.xml <error-page> <error-code>404</error-code> <location>/errors/404/</location> </error-page> The problem is that if the user goes to http://mydomain/bad/url it is redirected to http://mydoma...

Ignore fatal errors and DB exceptions in a PHP web service

I have a web service written in PHP, that returns JSON results. It works well and has been thoroughly tested. I needed to add logging to the service calls (who called and when). I implemented this using a SQLite database (for very small amount of data) and PDO. The one condition to the logging was that it should not harm the web servic...

Detecting if content was sent prior to a line in a php file in codeigniter

I'm trying to change the way the error files from system/application/errors work by logging the errors and showing a 404 page instead. However, sometimes the error occurs in the middle of a page and I need to display only the error page. I've tried to check if the headers are sent and cleaning the output buffer but it didn't work. Any s...

Eating Exceptions

I m parsing a file that has MalFormed data from time to time. and it s throwing an exception, i d like to recover from the exception and ignore the bad formatted data. What s the best way to do this? try{ // parse file }catch(Exception){ //eat it. } *EDIT:*I think, my question wasnt understood well. i d like to recover from the exc...

Variable Declaration Versus Error Checking: Which Comes First?

When writing a function I always have this confusion whether to check for errors first and declare the variables later (or) assign the parameters to local variables and then check for errors. Which of the following way is preferred and why? I usually stick to the first type. void DoSomething1(Object x, Object y){ // All sort of error...

How to handle this error caused by uploading a problematic JPEG?

I have a website where the public can upload JPEGs. Someone from the public was uploading an invalid JPEG that was causing the site to crash for them. PHP said... imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file I wasn't sure how to get around this, so I Google...

How can I access the name of the function generating an error or warning?

If a warning or error occurs, I would like to print the name of the function generating the error. tryCatch in R allows one to handle errors in a function call, perhaps it is part of the solution? For example, this could be in a context like: handleErr <-function(e) { print("you had an error in function:") print( WHAT CAN I P...

trigger_error vs. throwing exceptions

A similar question was asked here, but as the answers didn't answer my question, I'm asking: I've almost never used trigger_error, always thrown exceptions instead, since in my mind errors are legacy. But I've changed my mind, I think they can co-exist. There are cases when triggering errors make more sense. I'm updating this library, ...

custom errorhandler does not handle critical errors (php)

Hi. This is the main part of my errorhandler: function my_error_handler($errno, $errstr, $errfile, $errline){ $errno = $errno & error_reporting(); if($errno == 0) return; if(!defined('E_STRICT')) define('E_STRICT', 2048); if(!defined('E_RECOVERABLE_ERROR')) define('E_RECOVERABLE_ERROR', 4096); $error = "...

How do I refactor closing a stream in Java?

Due to my company's policy of using Eclipse and using Eclipse's code-autofix, the following code pattern appears excessively in the codebase: InputStream is = null; try { is = url.openConnection().getInputStream(); // ..... } catch (IOException e) { // handle error } finally { if (is != null) { try { ...