People leave companies all the time--but when you're a member of the senior executive team, or even the CEO, making an exit can be complicated. Sometimes you leave by choice; other times, not. Sometimes you've achieved your objectives; other times, your plans fall short of success. Regardless of the circumstances surrounding your departure, however, one thing is certain: People will be watching you on the way out. Employees, customers, partners, investors, and even future employers will all take note of your actions. So how do you leave the "right" way?

Here are three rules of thumb I find critical to ensuring your future success as a leader:

1. Have the right attitude and perspective--especially if you're exiting under less than ideal conditions. Look, no company leader is perfect. Ever. Yes, you need to be held accountable for how you do your job, but at the same time, business today in the short term has never been riskier. You've probably never had the luxury of time in which to craft the perfect strategies, the perfect go-to-market plans, and the perfect products. On the contrary, the very nature of your job requires that you be willing to act quickly and authoritatively, often with imperfect information. Sometimes you'll succeed at this, and sometimes you won't. So be it.

The good news is that the current economy holds plenty of opportunities for skilled C-level executives. You've no doubt learned valuable lessons in your current job that you can apply to the next one. In fact, I have a close relative who ended up starting a multi-million dollar business on his own after having to step down as CEO of another company. You never know what's waiting around the corner--so keep a healthy outlook when you leave.

2. Always be gracious. Odds are there are a number of people in your organization who have struggled like heck to make you and the company a success. Thank all of them. Tell your team members and employees that you sincerely appreciate their work on your behalf. You are where you are because of them.

At the same time, remember that they are where they are--facing the imminent departure of a senior executive--because of you. You can't control whether your replacement calls for a reorganization or brings in a new team, but you can assure people that if they, too, end up leaving the company or needing references down the road, you will continue to support them.

3. Be classy and honor your commitment. When you take an executive position, you make a commitment to do the best job you can do for as long as possible. You know that most companies invest a lot of time and resources to fill senior-level roles. And more importantly, many lives are disrupted to accommodate the strategy and plan of action of a new executive. In short, people are counting on you--and that doesn't just change instantly because you're leaving, no matter what the reason for your departure.

Afraid people will find out you were fired? Or that you didn't fulfill all expectations? Don't be--they're going to find out eventually anyway. Show your maturity from the onset of the process. Own up to what you couldn't accomplish. If you had a difference of opinion with your Board of Directors, shake their hands and wish them the best. Offer to work through the transition period, even if you aren't leaving by choice. You'll be helping the people who helped make you a success, and it's in the best interest of the company (and your equity, right?).

Leaving is never straightforward when you're at the top of a company's leadership ladder. Just look at Twitter CEO Dick Costolo, who stepped down a few weeks ago. He knew full well that if you just walk away, and you leave big projects undone, big investments uncompleted, and an organization without any succession plan, then the public will get distracted and the company will suffer. So he and the board put a plan in place together before he announced his resignation, and that plan seems to be working so far. I wish them luck.

If you're facing a similar predicament, I wish you luck as well. Just remember that walking away without the right attitude, without gratitude, and without class will get you a reputation in a very tight senior executive community as an opportunist--and, unlike a job, that kind of reputation is almost impossible to leave behind.