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 8884407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:03:15+00:00 2026-06-14T21:03:15+00:00

I’m trying to write a single if-else block within a catch method, but when

  • 0

I’m trying to write a single if-else block within a catch method, but when I get the error that ‘not all code paths return type int.’

Essentially, I’m writing a method that saves a UserName and Password to a Sql CE database, and I want to test for one specific error. (UserName already exists.) The UserName column is unique, so it will reliably throw a SqlCeException with NativeError = 25016. I want to display that with an error message, otherwise handle other exceptions in a more generic way.

My code is:

  try
  {
    //insert command  (This is where the duplicate column error is thrown)
    //Select @@Identity & Return it
  }
  catch (SqlCeException ex)
  {
   if (ex.NativeError == 25016)
        MessageBox.Show("Username already in use."); 
   else
     //whatever
  }

I’ve tried showing a different, more generic message and get the no return error.
I’ve tried throwing a new exception and catching it in another block. Same error.
I’ve tried returning -1 (as a sort of flag value). Same error.

There doesn’t appear to be a more specific error than SqlCeException for this specific case (Though I ma have just failed me debug-fu).

Any creative work-arounds?
Worst case, I’ll write a method that checks the DB for duplicate usernames before calling this method.

  • 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-14T21:03:16+00:00Added an answer on June 14, 2026 at 9:03 pm

    It looks like your method returns an int. You need to return a value of type int from your catch block.

      try
      {
        //insert command  (This is where the duplicate column error is thrown)
        //Select @@Identity & Return it
      }
      catch (SqlCeException ex)
      {
       if (ex.NativeError == 25016)
            MessageBox.Show("Username already in use."); 
       else
       {
         //whatever  
       }
       return -1;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.