I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2006-03-21 23:11:48-08 by cowanbill
Dynamic way to get specific exception name from object?
When catching an exception, the catch may be either the exception identified in the 'caught' method or a subclass. I would like to have a dynamic mechanism to get the actual class name for the exception object (e.g. "MyException::File::Open" subclass or "MyException::File"?). This would be useful in building diagnostic info to log or present to developer.

Suggestions for how to do this? Hopefully without hardcoding?

There are a several class and object methods described in the doc for Exception::Class. Available object method I missed?
Direct Responses: 2002 | Write a response
Posted on 2006-03-22 00:59:37-08 by jdhedden in response to 2001
Re: Dynamic way to get specific exception name from object?
You can use the 'caught' method with your base class (which defaults to Exception::Class::Base), and then use 'ref' on the caught exception.
eval { ... }; if (my $e = Exception::Class::Base->caught()) { print(STDERR "Caught an exception of type ", ref($e), "\n"); }
Direct Responses: 2004 | Write a response
Posted on 2006-03-22 05:31:17-08 by cowanbill in response to 2002
Re: Dynamic way to get specific exception name from object?
Thanks for your quick response! After reading your suggestion to use 'ref' function, I thought "so obvious". I was doing too much exception thinking and did not see the simple answer.
Direct Responses: Write a response