Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:26:54+00:00 2026-05-28T01:26:54+00:00

Take the following function as an example of what I want to do: public

  • 0

Take the following function as an example of what I want to do:

public function save() {
    $this->connect('wb');
    try {
        if(!$this->lock())
            throw new Exception("Unable to acquire configuration locks");
        if (!$backup = $this->backup())
            throw new Exception("Failed to create configuration backup");
        try {
            if(!fwrite($this->_pointer, $this->dump("string")));
                throw new Exception("Error occured while writing to configuration");
            $this->unlock();
            $this->disconnect();
        } catch (Exception $e) {
            if(rename ($backup, $this->_file))
                $e .= PHP_EOL."Successfully restored configuration from backup";
            else
                $e .= PHP_EOL."Failed to restore configuration from backup";
            $this->unlock();
            $this->disconnect();
            throw $e;
        }
    } catch (Exception $e) {
        echo PHP_EOL, $e->getMessage();
    }
}

I have nested try() and catch() statements. An exception is thrown from the inner-most and is caught, I then perform some functions and throw another exception. Notice where I write $e .=, I understand this is the incorrect syntax. What I want to do is append the string to the exception’s $e->getMessage().

How would I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:26:55+00:00Added an answer on May 28, 2026 at 1:26 am

    Create you own exception class and create method for appending string to the message.

    <?php
    class SuperException extends Exception
    {
        public function AppendToMessage($msg)
        {
            // $this->message is inherited from Exception class,
            // where it is protected field (member) of the class
            $this->message .= $msg;
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following function for example: private function connect($method, $target = $this->_config->db()) { try
Take for example the following controller/action: public function indexAction() { return $this->render('TestBundle:TestController:index.html.twig'); } I
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
Take the following example, I have a class public class SomeItem { public string
Take the following function as an example: void Changing(string var1, string var2, string var3)
I have a for-loop which performs the following function: Take a M by 8
The following function System.Threading.Thread.Sleep(); delay the thread in millisecond, and take the integer value
Take the following method (written in Ruby but this question could be applied to
Take the following property: public string Foo { get; private set; } Using reflection,
Let's say for example, I have the following javascript function that returns a boolean:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.