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

  • SEARCH
  • Home
  • 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 7943725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:21:19+00:00 2026-06-04T00:21:19+00:00

I have defined a simple int error code: #define my_error 20 Somewhere in my

  • 0

I have defined a simple int error code:

#define my_error 20

Somewhere in my code I throw this error:

throw my_error;

Now I want to try and catch this exception thrown:

try
{
    ...
    ...
}
catch (my_error)
{
    cout << "Error: my error";
}

Unfortunately the compiler doesn’t approve this:

  • syntax error : ‘constant’
  • catch handlers must specify one type
  • ‘try’ block starting on line ’34’ has no catch handlers

Is there a way to do 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-06-04T00:21:21+00:00Added an answer on June 4, 2026 at 12:21 am

    20 is not a type, so you can’t catch it. What you can do is filter the values in the catch block:

    catch (int exception)
    {
        if ( exception == 20 )
            cout << "Error: my error";
    }
    

    An even better approach would be to define your own exception:

    class MyException : public std::exception
    {
    }
    
    //...
    
    try
    {
       throw MyException();
    }
    catch(MyException& ex)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a defined a simple template class. In this class I define a
I have the following code: struct simple { simple (int a1, int a2) :
I have a small sample function: #define VALUE 0 int test(unsigned char x) {
I have defined a fieldset in HTML, and applied the following (simple) CSS rules
I have a pretty simple UIScrollView defined inside Interface Builder. I've pasted in some
I have a very simple dialog defined as: import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater;
Well, the question is kinda simple. I have a object defined as: public class
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as
I have a simple temp-table defined in SQL Server 2008 R2 representing a parent-child
I have a VERY simple 3D space defined in WPF, which defines a 3D

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.