NAME

MVC::Neaf::Exception - Exception class for Not Even A Framework.

DESCRIPTION

Currently internal signalling or MVC::Neaf is based on the exception mechanism. To avoid collisions with user's exceptions or Perl errors, these internal exceptions are blessed into this class.

Please see the neaf_err() function in MVC::Neaf.

By convention, die nnn and die MVC::Neaf::Exception-new( nnn )> will be treated exactly the same by Neaf.

CAUTION. This file is mostly used internally by Neaf and may change with little to no warning. Please file a bug/feature request demanding a more stable interface if you plan to rely on it.

CAVEAT EMPTOR.

METHODS

new( $@ || 500, %options )

new( %options )

Returns a new exception object.

%options may include any keys as well as some Neaf-like control keys:

  • -status - alias for first argument. If starts with 3 digits, will result in a "http error page" exception, otherwise is reset to 500 and reason is updated.

  • -reason - details about what happened

  • -location - indicates a redirection

  • -sudden - this was not an expected error (die 404 or redirect) This will automatically turn on if -status cannot be parsed.

  • -file - where error happened

  • -line - where error happened

  • -nocaller - don't try to determine error origin via caller

status()

Return error code.

is_sudden()

Tells whether error was unexpected.

EXPERIMENTAL. Name and meaning subject to change.

as_string()

Stringify.

Result will start with MVC::Neaf: if error was generated via die 404 or a redirect.

Otherwise it would look similar to the original -status.

make_reply( $request )

Create a Neaf-like default reply:

    {"status":400,"req_id":"FOOB4RED"}

Or

    See $location

if redirect.

reason()

Returns error message that was expected to cause the error.

file_and_line

Return " at /foo/bar line 42" suffix, if both file and line are available. Empty string otherwise.

TO_JSON()

Converts exception to JSON, so that it doesn't frighten View::JS.

LICENSE AND COPYRIGHT

Copyright 2016-2017 Konstantin S. Uvarin khedin@cpan.org.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.