{"record":{"id":"b6f4b4ac4c29b3cc","repo":"BoundaryML/baml","slug":"uncaught-throw-0","errorCode":null,"errorMessage":"uncaught throw: {0:?}","messagePattern":"uncaught throw: (.+?)","errorType":"exception","errorClass":"VmError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":434,"sourceCode":"            value,\n            profiler_kind: ProfilerErrorKind::Rethrow,\n            language_is_rethrow,\n            origin: VmUnwindOrigin::unresolved(source),\n        }\n    }\n\n    #[must_use]\n    pub const fn with_origin(mut self, origin: VmUnwindOrigin) -> Self {\n        self.origin = origin;\n        self\n    }\n}\n\n/// Any kind of virtual machine error.\n#[derive(Debug, Error, PartialEq, Clone)]\npub enum VmError {\n    /// Catchable (panics and error values) — internal signal for exception unwinding.\n    #[error(\"uncaught throw: {0:?}\")]\n    Thrown(VmThrown),\n    /// An exception that escaped all catch handlers, with captured stack trace.\n    #[error(\"uncaught throw: {value:?}\")]\n    ThrownUnhandled {\n        value: Value,\n        trace: Vec<StackFrame>,\n    },\n    /// Fatal VM errors\n    #[error(\"{0}\")]\n    InternalError(#[from] VmInternalError),\n    /// Fatal VM error with captured stack trace.\n    /// Produced by `exec()` wrapper from `InternalError`.\n    #[error(\"{}\", format_internal_error(source, trace))]\n    TracedInternalError {\n        source: VmInternalError,\n        trace: Vec<StackFrame>,\n    },\n}","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L416-L452","documentation":"VmError::Thrown wraps a VmThrown value representing a catchable throw (panic or error value) inside the BAML VM that was never caught. It is primarily an internal unwinding signal; when it surfaces to the user it means an exception raised in BAML code escaped without any matching catch handler.","triggerScenarios":"BAML code executes a throw/panic and no enclosing catch block matches; native functions raise catchable errors that bubble to the top of the VM; a thrown Value (e.g. a user-defined class instance) is not intercepted by any handler.","commonSituations":"Omitting a catch handler for fallible BAML logic; a runtime or client error (e.g. LlmClient failure) being re-thrown as a VM throw; user-defined exception classes thrown in helpers and never caught at the call site.","solutions":["Wrap the failing BAML expression/call in a catch handler appropriate to the thrown value type.","Inspect the debug-formatted VmThrown in the message to see exactly what was thrown and from where.","Fix the root cause (the operation that threw) once identified from the thrown value.","Add top-level error handling in the host when calling BAML functions so uncaught throws are reported cleanly."],"exampleFix":"// before: no handler\nlet r = risky();\n\n// after\nlet r = catch risky() {\n  case e => \"fallback\"\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match vm_result {\n    Err(BexError::Thrown(thrown)) => {\n        eprintln!(\"uncaught VM throw: {:?}\", thrown);\n    }\n    other => other?,\n}","preventionTips":["Add catch handlers around every fallible BAML call.","Log the debug formatting of VmThrown to identify throw sources.","Handle errors close to where they are raised rather than letting them escape.","Add a top-level handler in the host when invoking BAML entry points."],"tags":["baml","vm","uncaught-exception"],"backgroundTag":"invalid-state-transition","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}