In certain cases, it's correct for my app to die if it encounters a potentially dangerous condition... I'm working on a more detailed error reporting system, and among the things I want to list are; the object class that threw the error, and the method that threw the error. At the moment, all potentially dangerous objects have a method that 'builds' an error object, and all the potential 'die' situations call this method, something like this:

sub _procError{
  my($self,$processor,$fnc_ref,$err_desc) = @_;
  my($err_message) = {};
  $err_message->{detector} = $self;
  $err_message->{function} = $fnc_ref;
  $err_message->{description} = $err_desc;
  return $processor->criticalError($err_message);
}

#And if a failable condition is met within an object method:
return $self->_procError($fuser,FNC_HTACCESS,"The path $p_name didn't validate correctly") unless $dir_name;

The 'processor' object referenced in the _procError() function causes the system to shut down and displays the contents of that error object (after adding its own internal states to it) whenever criticalError() is called...

At the moment, I use a constant enumeration for the functions in each plugin module object (FNC_HTACCESS is a function name, and that constant is defined in the package, along with all other function names)....

This doesn't translate well to a meaningful notification of where the error was detected, without using a lookup or complex conditional within each object. Is there a way to just reference the 'name of the running function'? It would make this alot easier to implement =P

I don't want to instantiate a lookup table in every object regardless of errors, so it would otherwise be a case of building the lookup if or when an error occurs.

hey, no worries, i found the caller() function... even better i can call it retrospectively:

($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask) =
      caller(0); 
caller(0) : details about this function
caller(1) : details about the last function
caller(X) : etc

Now I only have one lookup; for 'internal' error type defintion... ^_-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.