SPVM::D...Handling(3)
π 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::StatementsSPVM::Document::Language::OperatorsSPVM::Document::LanguageSPVM::Document
π COPYRIGHT & LICENSE π
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
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms