SPVM::D...Handling(3)

πŸ“¦ version 0.990125, in alpine 3.24

πŸ’– NAME πŸ’–

SPVM::Document::Language::ExceptionHandling β€” Exception Handling in the SPVM Language

Okay bestie, this is the SPVM::D...Handling(3) page from the User Contributed Perl Documentation, and it is literally all about exception handling in the SPVM language. No cap.

🌸 DESCRIPTION 🌸

This doc describes exception handling in the SPVM language. Short, sweet, iconic. Periodt.

πŸ’… EXCEPTION HANDLING πŸ’…

Here’s the whole vibe, bestie: throwing, catching, and the exception variable. Let’s go. πŸ¦‹

πŸ”₯ Throwing Exception πŸ”₯

The die statement throws an exception. Like this:

die "This value is invalid.";

You can give a basic type ID to the die statement. If an exception is thrown, that basic type ID is set to eval_error_id. Behold:

die basic_type_id Error::System, "This value is invalid.";

You can also give a class name to the die statement. This is the same as the code above:

die Error::System "This value is invalid.";

If you don’t give a basic type ID and you don’t give a class name, it gets set to the basic type ID of Error class. Simple as that. πŸ’…

πŸŽ€ Catching Exception πŸŽ€

An eval block catches an exception. Like:

eval {
  die "This value is invalid.";
}

At the beginning of each eval block, undef is set to $@.

Also at the beginning of each eval block, 0 is set to eval_error_id.

If an exception is thrown, the message passed to the die statement is set to $@, and the basic type ID passed to the die statement is set to eval_error_id. Okay so here’s the code:

if ($@) {
  # Do something if an exception is thrwon
}

# If you need to check eval_error_id, write the following code.
if ($@) {
  if (eval_error_id isa_error Error::System) {

  }
}

That thrwon typo? It’s in the original, bestie β€” I’m not fixing it. πŸ’€

$@ could be overwritten by the other operations, so it is good to save it into a local variable:

if (my $error = $@) {

}

πŸ¦‹ Exception Variable πŸ¦‹

$@ is the exception variable. It’s used to save a message for an exception.

$@

The type is string type.

Using the assignment operator, the value of the exception variable can be set:

$@ = "Error Message";

$@ = undef;

The exception variable is a stack variable(not a global variable).

If a new stack is created for a thread, exception variables exist for each thread. Iykyk. 🧚

🌈 SEE ALSO 🌈

Go read these too, bestie:

  • SPVM::Document::Language::Statements
  • SPVM::Document::Language::Operators
  • SPVM::Document::Language
  • SPVM::Document

Copyright (c) 2023 Yuki Kimoto

MIT License

That’s the legal bit, periodt. πŸ’–


That’s the whole page, bestie! Source/version: perl v5.42.2. Date: 2026-02-03. Now go handle those exceptions with main character energy. 🫢

πŸ“¦ where this page comes from