You can use the throwError() function to throw custom errors to your heart's content.
@@#error;@@
<<script>>
postdisplay['error'] = function (t) {
delete postdisplay[t];
throwError('#error', 'No player character.', 'You appear to be kind of mostly dead. Sorry you had to find out like this.');
}
<</script>>
Note that because the error message needs to target something on the DOM, you need to wait for the rendering to finish before you can do it. A postdisplay task (as above) works, but so would a passage event, a link/button, or even a <<timed>> macro.
Note: This is an undocumented function, so it's not officially supported, and could change, be removed, be made unavailable, etc in future SugarCube versions.