How can you handle exceptions or unexpected cases when manipulating strings in PHP?

When manipulating strings in PHP, it is important to anticipate exceptions or unexpected cases to prevent errors in your code. One way to handle this is by using conditional statements or built-in functions to check for specific conditions before performing string operations. Additionally, you can use try-catch blocks to catch and handle any exceptions that may arise during string manipulation.

<?php
$string = "Hello, World!";
$newString = "";

if(strlen($string) > 0) {
    // Perform string manipulation operations here
    $newString = strtoupper($string);
} else {
    echo "String is empty!";
}

echo $newString;
?>